TTime/backend/internal/handlers/reports/GetUnsignedReports.go

46 lines
1.3 KiB
Go
Raw Normal View History

package reports
import (
db "ttime/internal/database"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/golang-jwt/jwt/v5"
)
func GetUnsignedReports(c *fiber.Ctx) error {
// Extract the necessary parameters from the token
user := c.Locals("user").(*jwt.Token)
claims := user.Claims.(jwt.MapClaims)
projectManagerUsername := claims["name"].(string)
// Extract project name and week from query parameters
projectName := c.Params("projectName")
log.Info("Getting unsigned reports for")
if projectName == "" {
log.Info("Missing project name")
return c.Status(400).SendString("Missing project name")
}
// Get the project manager's ID
isProjectManager, err := db.GetDb(c).IsProjectManager(projectManagerUsername, projectName)
if err != nil {
log.Info("Failed to get project manager ID")
return c.Status(500).SendString("Failed to get project manager ID")
}
log.Info("User is Project Manager: ", isProjectManager)
// Call the database function to get the unsigned weekly reports
reports, err := db.GetDb(c).GetUnsignedWeeklyReports(projectName)
if err != nil {
log.Info("Error getting unsigned weekly reports:", err)
return c.Status(500).SendString(err.Error())
}
log.Info("Returning unsigned reports")
// Return the list of unsigned reports
return c.JSON(reports)
}