Skip to content

Commit

Permalink
Merge pull request #171 from AkshatGupta15/main
Browse files Browse the repository at this point in the history
Intialised mailing system for every action on pvfs
  • Loading branch information
bmerchant22 authored Aug 28, 2024
2 parents 6004a04 + 0a641c3 commit 068c725
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 61 deletions.
73 changes: 44 additions & 29 deletions application/admin.pvf.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func sendVerificationLinkForPvfHandler(mail_channel chan mail.Mail) gin.HandlerF
"https://placement.iitk.ac.in/verify?token=" + token + "&rcid=" + util.ParseString(rid) + "\n\n" +
"Your prompt response is appreciated to ensure timely processing of " + pvf.Name + "'s placement applications.\n\n" +
"Please note:\n" +
"The PVF verifies the student's involvement and contributions to the project/internship. " +
"Only projects/internships conducted with IIT Kanpur faculty or external organizations require verification. " +
"The PVF verifies the student's involvement and contributions to the project/internship. \n" +
"Only projects/internships conducted with IIT Kanpur faculty or external organizations require verification. \n" +
"If you have any questions regarding the PVF process, please don't hesitate to contact the Students' Placement Office at [email protected].\n\n" +
"Thank you for your time and support."

Expand Down Expand Up @@ -183,39 +183,54 @@ func deletePVFHandler(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"status": "deleted PVF"})
}

func putPVFHandlerForAdmin(ctx *gin.Context) {
var jp PVF
func putPVFHandlerForAdmin(mail_channel chan mail.Mail) gin.HandlerFunc {
return func(ctx *gin.Context) {
var pvf PVF

rid, err := util.ParseUint(ctx.Param("rid"))
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
// rid, err := util.ParseUint(ctx.Param("rid"))
// if err != nil {
// ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }

err = ctx.ShouldBindJSON(&jp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err := ctx.ShouldBindJSON(&pvf)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

if jp.ID == 0 {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "id is required"})
return
}
if pvf.ID == 0 {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "id is required"})
return
}

var oldJp PVF
err = fetchPvfForAdmin(ctx, rid, jp.ID, &oldJp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var oldPvf PVF

err = updatePVF(ctx, &jp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
// err = fetchPvfForAdmin(ctx, rid, oldPvf.ID, &oldPvf)
err = fetchPVF(ctx, pvf.ID, &oldPvf)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

err = updatePVF(ctx, &pvf)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
message := "Dear " + oldPvf.Name + ",\n\n" +

"Action has been taken on your Project Verification Form. Kindly check the status on the RAS Portal." +
"\n\n" +
"Regards,\n" +
"Students' Placement Team, IIT kanpur"
// logrus.Infof("EmaIL : %s OR %s", pvf.IITKEmail, oldPvf.IITKEmail)
mail_channel <- mail.GenerateMail(oldPvf.IITKEmail,
"Project Verification Update for "+oldPvf.Name+"'s Internship/Project",
message,
)
ctx.JSON(http.StatusOK, gin.H{"status": "Updated PVF with id " + util.ParseString(pvf.ID)})
}
ctx.JSON(http.StatusOK, gin.H{"status": "Updated PVF with id " + util.ParseString(jp.ID)})
}

func getAllStudentPvfHandler(ctx *gin.Context) {
Expand Down
6 changes: 3 additions & 3 deletions application/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func AdminRouter(mail_channel chan mail.Mail, r *gin.Engine) {
admin.DELETE("event/:eid/student/:sid", deleteStudentFromEventHandler)

admin.GET("/pvf", getAllPvfForAdminHandler)
admin.PUT("/pvf", putPVFHandlerForAdmin)
admin.PUT("/pvf", putPVFHandlerForAdmin(mail_channel))
admin.GET("/pvf/:pid", getPvfForAdminHandler)
admin.GET("pvf/:pid/verification/send", sendVerificationLinkForPvfHandler(mail_channel))
admin.GET("pvf/student/:sid/verification/send", sendVerificationLinkForStudentAllPvfHandler(mail_channel))
Expand Down Expand Up @@ -113,12 +113,12 @@ func CompanyRouter(r *gin.Engine) {
}
}

func PvfVerificationRouter(r *gin.Engine) {
func PvfVerificationRouter(mail_channel chan mail.Mail, r *gin.Engine) {
pvf := r.Group("/api/verification")
pvf.Use()
{
pvf.GET("/pvf", getPvfForVerificationHandler)
// pvf.PUT("pvf/:pid/verify", verifyPvfHandler)
pvf.PUT("/pvf", putPVFHandler)
pvf.PUT("/pvf", putPVFHandler(mail_channel))
}
}
83 changes: 57 additions & 26 deletions application/verify.pvf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/spo-iitk/ras-backend/mail"
"github.com/spo-iitk/ras-backend/middleware"
"github.com/spo-iitk/ras-backend/util"
)
Expand Down Expand Up @@ -33,38 +34,68 @@ func getPvfForVerificationHandler(ctx *gin.Context) {
ctx.JSON(http.StatusOK, jps)
}

func putPVFHandler(ctx *gin.Context) {
var jp PVF
func putPVFHandler(mail_channel chan mail.Mail) gin.HandlerFunc {
return func(ctx *gin.Context) {
var pvf PVF

err := ctx.ShouldBindJSON(&jp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
pid := middleware.GetPVFID(ctx)
err := ctx.ShouldBindJSON(&pvf)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
pid := middleware.GetPVFID(ctx)

jp.ID = pid
pvf.ID = pid

if jp.ID == 0 {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "id is required"})
return
}
if pvf.ID == 0 {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "id is required"})
return
}

var oldJp PVF
err = fetchPVF(ctx, jp.ID, &oldJp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var oldJp PVF
err = fetchPVF(ctx, pvf.ID, &oldJp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

// jp.ActionTakenBy = middleware.GetUserID(ctx)
// jp.ActionTakenBy = middleware.GetUserID(ctx)

// publishNotice := oldJp.Deadline == 0 && jp.Deadline != 0
// publishNotice := oldJp.Deadline == 0 && jp.Deadline != 0

err = updatePVF(ctx, &pvf)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var action string
if pvf.IsVerified.Bool {
action = "APPROVED"
} else {
action = "DENIED"
}
messageMentor := "Dear " + oldJp.MentorName + ",\n\n" +
"The action " + action + " on the Project Verification Form of the " + oldJp.Name + " has been taken.\n\n" +
"If you have not done this action please reach out to [email protected]\n\n" +
"Regards,\n" +
"Students' Placement Team, IIT kanpur"

mail_channel <- mail.GenerateMail(oldJp.MentorEmail,
"Project Verification Update for "+oldJp.Name+"'s Internship/Project",
messageMentor,
)
messageStudent := "Dear " + oldJp.Name + ",\n\n" +

"Action has been taken on your Project Verification Form. Kindly check the status on the RAS Portal." +
"\n\n" +
"Regards,\n" +
"Students' Placement Team, IIT kanpur"

mail_channel <- mail.GenerateMail(oldJp.IITKEmail,
"Project Verification Update for "+oldJp.Name+"'s Internship/Project",
messageStudent,
)
ctx.JSON(http.StatusOK, gin.H{"status": "Updated PVF with id " + util.ParseString(pvf.ID)})

err = updatePVF(ctx, &jp)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
ctx.JSON(http.StatusOK, gin.H{"status": "Updated PVF with id " + util.ParseString(jp.ID)})
}
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func main() {
return adminCompanyServer().ListenAndServe()
})
g.Go(func() error {
return verificationServer().ListenAndServe()
return verificationServer(mail_channel).ListenAndServe()
})

log.Println("Starting Server...")
Expand Down
5 changes: 3 additions & 2 deletions cmd/verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"github.com/spo-iitk/ras-backend/application"
"github.com/spo-iitk/ras-backend/mail"
"github.com/spo-iitk/ras-backend/middleware"
)

func verificationServer() *http.Server {
func verificationServer(mail_channel chan mail.Mail) *http.Server {
PORT := viper.GetString("PORT.VERIFICATION")
fmt.Print(PORT)
engine := gin.New()
Expand All @@ -19,7 +20,7 @@ func verificationServer() *http.Server {
engine.Use(gin.CustomRecovery(recoveryHandler))
engine.Use(gin.Logger())

application.PvfVerificationRouter(engine)
application.PvfVerificationRouter(mail_channel, engine)

server := &http.Server{
Addr: ":" + PORT,
Expand Down

0 comments on commit 068c725

Please sign in to comment.