package user import ( "strings" "clickandjoin.app/managementsystem/modules/scylladb" "clickandjoin.app/managementsystem/modules/structs" gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/cnjvalidator" "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper/dbstructs" "github.com/gofiber/fiber/v2" ) func UpdateUser(c *fiber.Ctx) error { // swagger:operation PATCH /user/:userId user userUpdateUser // --- // summary: Update an user // consumes: // - application/json // produces: // - application/json // responses: // '200': // schema: // "$ref": "#/definitions/UsersResponse" // '500': // description: Internal server error var params structs.UserIdParam if err := c.ParamsParser(¶ms); err != nil { gocnjhelper.LogErrorf("Failed to parse params %s", err) return c.Status(fiber.StatusBadRequest).JSON(err) } errValidation := cnjvalidator.ValidateStruct(params) if errValidation != nil { return c.Status(fiber.StatusBadRequest).JSON(errValidation) } var body structs.UpdateUserRequest if err := c.BodyParser(&body); err != nil { gocnjhelper.LogErrorf("Failed to parse request data %s", err) return c.Status(fiber.StatusBadRequest).JSON(err) } errValidation = cnjvalidator.ValidateStruct(body) if errValidation != nil { return c.Status(fiber.StatusBadRequest).JSON(errValidation) } updatedUser := dbstructs.User{ Id: params.UserId, Username: body.Username, AccountName: body.AccountName, AccountNameLc: strings.ToLower(body.AccountName), Email: body.Email, Description: body.Description, AccountStatus: body.AccountStatus, } if err := scylladb.Session.Query(gocnjhelper.DbMUsers.Update("username", "account_name", "account_name_lc", "email", "description", "account_status")).BindStruct(updatedUser).ExecRelease(); err != nil { gocnjhelper.LogErrorf("Failed to update user, err: %s", err.Error()) return c.SendStatus(fiber.StatusInternalServerError) } return c.SendStatus(fiber.StatusOK) }