Handler ListAllUsersProject in global_state.go added for GetAllUsersProject in db.go

This commit is contained in:
dDogge 2024-03-14 22:56:50 +01:00
parent 34ad6ac777
commit f2a4c417aa

View file

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