Added GetWeeklyReportsUser function and handler, also corresponding tests to both GetWeeklyReportsUser and handler added

This commit is contained in:
dDogge 2024-03-19 19:04:45 +01:00
parent 2f3730ca90
commit 2b41085865
7 changed files with 131 additions and 0 deletions

View file

@ -20,6 +20,7 @@ type GlobalState interface {
GetProject(c *fiber.Ctx) error
AddUserToProjectHandler(c *fiber.Ctx) error
PromoteToAdmin(c *fiber.Ctx) error
GetWeeklyReportsUserHandler(c *fiber.Ctx) error
// GetProject(c *fiber.Ctx) error // To get a specific project
// UpdateProject(c *fiber.Ctx) error // To update a project
// DeleteProject(c *fiber.Ctx) error // To delete a project

View file

@ -114,3 +114,22 @@ func (gs *GState) SignReport(c *fiber.Ctx) error {
return c.Status(200).SendString("Weekly report signed successfully")
}
// 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")
projectName := c.Params("projectName")
// 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)
return c.Status(500).SendString(err.Error())
}
log.Info("Returning weekly reports for user:", username, "in project:", projectName)
// Return the list of reports as JSON
return c.JSON(reports)
}