package reports import ( "strconv" db "ttime/internal/database" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/log" "github.com/golang-jwt/jwt/v5" ) func UnsignReport(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 report ID from the path reportId, err := strconv.Atoi(c.Params("reportId")) if err != nil { log.Info("Invalid report ID") return c.Status(400).SendString("Invalid report ID") } // Get the project manager's ID projectManagerID, err := db.GetDb(c).GetUserId(projectManagerUsername) if err != nil { log.Info("Failed to get project manager ID for user: ", projectManagerUsername) return c.Status(500).SendString("Failed to get project manager ID") } // Call the database function to sign the weekly report err = db.GetDb(c).UnsignWeeklyReport(reportId, projectManagerID) if err != nil { log.Info("Error Unsigning weekly report:", err) return c.Status(500).SendString(err.Error()) } log.Info("Project manager ID: ", projectManagerID, " signed report ID: ", reportId) return c.Status(200).SendString("Weekly report unsigned successfully") }