Skip to content

Commit

Permalink
Added PVF routes and handlers (Student Side)
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshatGupta15 committed Jun 26, 2024
1 parent 2172df4 commit 0f5329c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion application/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions application/db.pvf.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions application/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
3 changes: 3 additions & 0 deletions application/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
57 changes: 57 additions & 0 deletions application/student.pvf.go
Original file line number Diff line number Diff line change
@@ -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)

}

0 comments on commit 0f5329c

Please sign in to comment.