Handler ProjectRoleChange in global_state.go added for ChangeUserRole in db.go

This commit is contained in:
dDogge 2024-03-14 23:06:10 +01:00
parent f2a4c417aa
commit 2409598c6e

View file

@ -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)
}