From 018dc24516d5a398d3725bc68be988eb40ec9436 Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Fri, 15 Mar 2024 15:28:45 +0100 Subject: [PATCH] Handler for GetProject from db.go added in global_stage.go --- backend/internal/handlers/global_state.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index fea0dfd..91d46a9 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -1,6 +1,7 @@ package handlers import ( + "strconv" "time" "ttime/internal/database" "ttime/internal/types" @@ -225,3 +226,24 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error { // Return a success message return c.SendStatus(fiber.StatusOK) } + +// GetProject retrieves a specific project by its ID +func (gs *GState) GetProject(c *fiber.Ctx) error { + // Extract the project ID from the request parameters or body + projectID := c.Params("projectID") + + // Parse the project ID into an integer + projectIDInt, err := strconv.Atoi(projectID) + if err != nil { + return c.Status(400).SendString("Invalid project ID") + } + + // Get the project from the database by its ID + project, err := gs.Db.GetProject(projectIDInt) + if err != nil { + return c.Status(500).SendString(err.Error()) + } + + // Return the project as JSON + return c.JSON(project) +}