-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from Abhimanyu-dev/main
Added document clarification route
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters