Handler for SignReport added and corresponding test in testing.pu added

This commit is contained in:
dDogge 2024-03-18 16:01:00 +01:00
parent 3a3690e3da
commit 9ad89d6063
2 changed files with 141 additions and 15 deletions

View file

@ -64,30 +64,42 @@ func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error {
return c.JSON(report)
}
type ReportId struct {
ReportId int
}
func (gs *GState) SignReport(c *fiber.Ctx) error {
println("Signing report...")
// Extract the necessary parameters from the token
user := c.Locals("user").(*jwt.Token)
claims := user.Claims.(jwt.MapClaims)
managerUsername := claims["name"].(string)
projectManagerUsername := claims["name"].(string)
// Extract the report ID and project manager ID from request parameters
reportID, err := strconv.Atoi(c.Params("reportId"))
if err != nil {
return c.Status(400).SendString("Invalid report ID")
// Extract report ID from the request query parameters
// reportID := c.Query("reportId")
rid := new(ReportId)
if err := c.BodyParser(rid); err != nil {
return err
}
println("Signing report for: ", rid.ReportId)
// reportIDInt, err := strconv.Atoi(rid.ReportId)
// println("Signing report for: ", rid.ReportId)
// if err != nil {
// return c.Status(400).SendString("Invalid report ID")
// }
// Call the database function to get the project manager ID
managerID, err := gs.Db.GetUserId(managerUsername)
// Get the project manager's ID
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
if err != nil {
return c.Status(500).SendString("Failed to get project manager ID")
}
println("blabla", projectManagerID)
// Call the database function to sign the weekly report
err = gs.Db.SignWeeklyReport(reportID, managerID)
err = gs.Db.SignWeeklyReport(rid.ReportId, projectManagerID)
if err != nil {
return c.Status(500).SendString("Failed to sign the weekly report: " + err.Error())
return c.Status(500).SendString(err.Error())
}
// Return success response
return c.Status(200).SendString("Weekly report signed successfully")
}