Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added document clarification route #163

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading