diff --git a/application/config.go b/application/config.go index 7703b3e..d2b9c36 100644 --- a/application/config.go +++ b/application/config.go @@ -33,7 +33,7 @@ func openConnection() { db = database err = db.AutoMigrate(&Proforma{}, &ApplicationQuestion{}, &ApplicationQuestionAnswer{}, - &ProformaEvent{}, &EventCoordinator{}, &EventStudent{}, &ApplicationResume{}) + &ProformaEvent{}, &EventCoordinator{}, &EventStudent{}, &ApplicationResume{}, &PVF{}) if err != nil { logrus.Fatal("Failed to migrate application database: ", err) panic(err) diff --git a/application/db.pvf.go b/application/db.pvf.go new file mode 100644 index 0000000..83d7df7 --- /dev/null +++ b/application/db.pvf.go @@ -0,0 +1,27 @@ +package application + +import "github.com/gin-gonic/gin" + +func createPVF(ctx *gin.Context, pvf *PVF) error { + tx := db.WithContext(ctx).Create(pvf) + return tx.Error +} + +func fetchPvfForStudent(ctx *gin.Context, sid uint, rid uint, jps *[]PVF) error { + tx := db.WithContext(ctx). + // Where("student_recruitment_cycle_id = ? AND recruitment_cycle_id = ?", sid, rid). + Select( + "id", + "company_university_name", + "role", + "duration", + "description", + "mentor_name", + "mentor_designation", + "mentor_email", + "is_verified", + ). + Order("id ASC"). + Find(jps) + return tx.Error +} diff --git a/application/model.go b/application/model.go index 80fbd43..136804b 100644 --- a/application/model.go +++ b/application/model.go @@ -126,3 +126,18 @@ type ApplicationResume struct { ResumeID uint `json:"resume_id"` Resume string `json:"resume"` } + +type PVF struct { + gorm.Model + StudentRecruitmentCycleID uint `json:"student_recruitment_cycle_id" gorm:"index;->;<-:create"` + CompanyUniversityName string `json:"company_university_name"` + Role string `json:"role"` + Duration string `json:"duration"` + Description string `json:"description"` + MentorName string `json:"mentor_name"` + MentorDesignation string `json:"mentor_designation"` + MentorEmail string `json:"mentor_email"` + IsApproved sql.NullBool `json:"is_approved" gorm:"index;default:NULL"` + IsVerified sql.NullBool `json:"is_verified" gorm:"index;default:NULL"` + RecruitmentCycleID uint `json:"recruitment_cycle_id" gorm:"index;->;<-:create"` +} diff --git a/application/router.go b/application/router.go index 1824690..88942a7 100644 --- a/application/router.go +++ b/application/router.go @@ -61,6 +61,9 @@ func StudentRouter(mail_channel chan mail.Mail, r *gin.Engine) { student.GET("/proforma/:pid", getProformaForStudentHandler) student.GET("/proforma/:pid/event", getEventsByProformaForStudentHandler) + student.POST("/pvf", postPvfForStudentHandler) + student.GET("/pvf", getPvfForStudentHandler) + student.GET("/opening", getProformasForEligibleStudentHandler) student.GET("/opening/:pid", getApplicationHandler) student.POST("/opening/:pid", postApplicationHandler(mail_channel)) diff --git a/application/student.pvf.go b/application/student.pvf.go new file mode 100644 index 0000000..c2fb8e2 --- /dev/null +++ b/application/student.pvf.go @@ -0,0 +1,57 @@ +package application + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/sirupsen/logrus" + "github.com/spo-iitk/ras-backend/middleware" + "github.com/spo-iitk/ras-backend/util" +) + +func postPvfForStudentHandler(ctx *gin.Context) { + sid := getStudentRCID(ctx) + if sid == 0 { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "SRCID not found"}) + return + } + var pvf PVF + err := ctx.ShouldBindJSON(&pvf) + if err != nil { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + pvf.StudentRecruitmentCycleID = sid + err = createPVF(ctx, &pvf) + if err != nil { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + user := middleware.GetUserID(ctx) + + logrus.Infof("%v created \a proforma with id %d", user, pvf.ID) + ctx.JSON(http.StatusOK, gin.H{"pid": pvf.ID}) + +} + +func getPvfForStudentHandler(ctx *gin.Context) { + sid := getStudentRCID(ctx) + if sid == 0 { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "SRCID not found"}) + return + } + rid, err := util.ParseUint(ctx.Param("rid")) + if err != nil { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + var jps []PVF + err = fetchPvfForStudent(ctx, sid, rid, &jps) + if err != nil { + ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(http.StatusOK, jps) + +}