From 2409598c6e480b044bfd10969f2d31d67708a3bb Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Thu, 14 Mar 2024 23:06:10 +0100 Subject: [PATCH] Handler ProjectRoleChange in global_state.go added for ChangeUserRole in db.go --- backend/internal/handlers/global_state.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index 0d49610..fea0dfd 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -35,6 +35,7 @@ type GlobalState interface { IncrementButtonCount(c *fiber.Ctx) error // For demonstration purposes ListAllUsers(c *fiber.Ctx) error // To get a list of all users in the application database ListAllUsersProject(c *fiber.Ctx) error // To get a list of all users for a specific project + ProjectRoleChange(c *fiber.Ctx) error // To change a users role in a project } // "Constructor" @@ -208,3 +209,19 @@ func (gs *GState) ListAllUsersProject(c *fiber.Ctx) error { // Return the list of users as JSON return c.JSON(users) } + +// ProjectRoleChange is a handler that changes a user's role within a project +func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error { + // Extract the necessary parameters from the request + username := c.Params("username") + projectName := c.Params("projectName") + role := c.Params("role") + + // Change the user's role within the project in the database + if err := gs.Db.ChangeUserRole(username, projectName, role); err != nil { + return c.Status(500).SendString(err.Error()) + } + + // Return a success message + return c.SendStatus(fiber.StatusOK) +}