Skip to content

Commit

Permalink
Merge pull request #163 from Abhimanyu-dev/main
Browse files Browse the repository at this point in the history
Added document clarification route
  • Loading branch information
yashlm authored Jul 7, 2024
2 parents efc77fa + 14f7a53 commit df614c0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions student/admin.clarification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package student

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"
)

type postClarificationRequest struct {
Clarification string `json:"clarification" binding:"required"`
}

func postClarificationHandler(mail_channel chan mail.Mail) gin.HandlerFunc {
return func(ctx *gin.Context) {
sid, err := util.ParseUint(ctx.Param("sid"))
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

var student Student
err = getStudentByID(ctx, &student, sid)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

var request postClarificationRequest
err = ctx.ShouldBindJSON(&request)
if err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

mail_channel <- mail.GenerateMail(student.IITKEmail, "Asking Clarification", request.Clarification)
mail_channel <- mail.GenerateMail(
middleware.GetUserID(ctx),
"Clarification Requested from "+student.Name,
"Dear "+middleware.GetUserID(ctx)+
"Clarification was requested from "+student.Name+
"\nSent Mail:\n"+
request.Clarification)

ctx.JSON(http.StatusOK, gin.H{"status": "Clarification Mail sent"})
}
}
1 change: 1 addition & 0 deletions student/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func AdminRouter(mail_channel chan mail.Mail, r *gin.Engine) {
admin.PUT("/:sid/verify", verifyStudentHandler)
admin.GET("/:sid/history", ras.PlaceHolderController)

admin.POST("/:sid/clarification", postClarificationHandler(mail_channel))
admin.GET("/:sid/documents", getDocumentHandler)
admin.PUT("/document/:docid/verify", putDocumentVerifyHandler(mail_channel))
admin.GET("/documents", getAllDocumentHandler)
Expand Down

0 comments on commit df614c0

Please sign in to comment.