package projects import ( db "ttime/internal/database" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/log" "github.com/golang-jwt/jwt/v5" ) // AddUserToProjectHandler is a handler that adds a user to a project with a specified role func AddUserToProjectHandler(c *fiber.Ctx) error { user := c.Locals("user").(*jwt.Token) claims := user.Claims.(jwt.MapClaims) pm_name := claims["name"].(string) project := c.Params("projectName") username := c.Query("userName") // Check if the user is a project manager isPM, err := db.GetDb(c).IsProjectManager(pm_name, project) if err != nil { log.Info("Error checking if user is project manager:", err) return c.Status(500).SendString(err.Error()) } if !isPM { log.Info("User: ", pm_name, " is not a project manager in project: ", project) return c.Status(403).SendString("User is not a project manager") } // Add the user to the project with the specified role err = db.GetDb(c).AddUserToProject(username, project, "member") if err != nil { log.Info("Error adding user to project:", err) return c.Status(500).SendString(err.Error()) } // Return success message log.Info("User : ", username, " added to project: ", project) return c.SendStatus(fiber.StatusOK) }