diff --git a/backend/internal/handlers/handlers_report_related.go b/backend/internal/handlers/handlers_report_related.go index b745400..47d076d 100644 --- a/backend/internal/handlers/handlers_report_related.go +++ b/backend/internal/handlers/handlers_report_related.go @@ -117,14 +117,22 @@ func (gs *GState) SignReport(c *fiber.Ctx) error { // GetWeeklyReportsUserHandler retrieves all weekly reports for a user in a specific project func (gs *GState) GetWeeklyReportsUserHandler(c *fiber.Ctx) error { - // Extract necessary parameters from the request - username := c.Params("username") + // Extract the necessary parameters from the token + user := c.Locals("user").(*jwt.Token) + claims := user.Claims.(jwt.MapClaims) + username := claims["name"].(string) + + // Extract necessary (path) parameters from the request projectName := c.Params("projectName") + // TODO: Here we need to check whether the user is a member of the project + // If not, we should return an error. On the other hand, if the user not a member, + // the returned list of reports will (should) allways be empty. + // Retrieve weekly reports for the user in the project from the database reports, err := gs.Db.GetWeeklyReportsUser(username, projectName) if err != nil { - log.Info("Error getting weekly reports for user:", err) + log.Error("Error getting weekly reports for user:", username, "in project:", projectName, ":", err) return c.Status(500).SendString(err.Error()) } diff --git a/backend/main.go b/backend/main.go index c5ac0bb..dc4bf0a 100644 --- a/backend/main.go +++ b/backend/main.go @@ -97,7 +97,7 @@ func main() { server.Put("/api/changeUserName", gs.ChangeUserName) server.Post("/api/promoteToAdmin", gs.PromoteToAdmin) server.Get("/api/users/all", gs.ListAllUsers) - server.Get("/api/getWeeklyReportsUser", gs.GetWeeklyReportsUserHandler) + server.Get("/api/getWeeklyReportsUser/:projectName", gs.GetWeeklyReportsUserHandler) server.Get("api/checkIfProjectManager", gs.IsProjectManagerHandler) server.Post("/api/ProjectRoleChange", gs.ProjectRoleChange) server.Get("/api/getUsersProject/:projectName", gs.ListAllUsersProject)