From 34ad6ac777ad9815c594c936052b83fb9ead9747 Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Thu, 14 Mar 2024 22:48:06 +0100 Subject: [PATCH 1/3] Handler ListAllUsers in global_state.go added for GetAllUserApplication in db.go --- backend/internal/handlers/global_state.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index 0f3fcc0..011d578 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -33,6 +33,7 @@ type GlobalState interface { // SignCollection(c *fiber.Ctx) error // To sign a collection GetButtonCount(c *fiber.Ctx) error // For demonstration purposes IncrementButtonCount(c *fiber.Ctx) error // For demonstration purposes + ListAllUsers(c *fiber.Ctx) error // To get a list of all users in the application database } // "Constructor" @@ -180,3 +181,14 @@ func (gs *GState) GetUserProjects(c *fiber.Ctx) error { // Return a json serialized list of projects return c.JSON(projects) } + +func (gs *GState) ListAllUsers(c *fiber.Ctx) error { + // Get all users from the database + users, err := gs.Db.GetAllUsersApplication() + if err != nil { + return c.Status(500).SendString(err.Error()) + } + + // Return the list of users as JSON + return c.JSON(users) +} From f2a4c417aa68285fa77e190faabecdbc70714cbc Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Thu, 14 Mar 2024 22:56:50 +0100 Subject: [PATCH 2/3] Handler ListAllUsersProject in global_state.go added for GetAllUsersProject in db.go --- backend/internal/handlers/global_state.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index 011d578..0d49610 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -34,6 +34,7 @@ type GlobalState interface { GetButtonCount(c *fiber.Ctx) error // For demonstration purposes 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 } // "Constructor" @@ -182,6 +183,7 @@ func (gs *GState) GetUserProjects(c *fiber.Ctx) error { return c.JSON(projects) } +// ListAllUsers is a handler that returns a list of all users in the application database func (gs *GState) ListAllUsers(c *fiber.Ctx) error { // Get all users from the database users, err := gs.Db.GetAllUsersApplication() @@ -192,3 +194,17 @@ func (gs *GState) ListAllUsers(c *fiber.Ctx) error { // Return the list of users as JSON return c.JSON(users) } + +func (gs *GState) ListAllUsersProject(c *fiber.Ctx) error { + // Extract the project name from the request parameters or body + projectName := c.Params("projectName") + + // Get all users associated with the project from the database + users, err := gs.Db.GetAllUsersProject(projectName) + if err != nil { + return c.Status(500).SendString(err.Error()) + } + + // Return the list of users as JSON + return c.JSON(users) +} From 2409598c6e480b044bfd10969f2d31d67708a3bb Mon Sep 17 00:00:00 2001 From: dDogge <> Date: Thu, 14 Mar 2024 23:06:10 +0100 Subject: [PATCH 3/3] 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) +}