MCPcopy Create free account
hub / github.com/devinterface/startersaas-go-api / Update

Method Update

endpoints/user.endpoint.go:163–191  ·  view source on GitHub ↗

Update function

(ctx *fiber.Ctx)

Source from the content-addressed store, hash-verified

161
162// Update function
163func (userEndpoint *UserEndpoint) Update(ctx *fiber.Ctx) error {
164 me, _ := userEndpoint.CurrentUser(ctx)
165 if can := userEndpoint.Can(ctx, models.AdminRole); !can {
166 return ctx.Status(401).JSON(fiber.Map{
167 "message": "You are not authorized to perform this action",
168 })
169 }
170
171 var inputMap = make(map[string]interface{})
172 ctx.BodyParser(&inputMap)
173
174 v := validate.Map(inputMap)
175 v.StringRule("name", "alpha")
176 v.StringRule("surname", "alpha")
177 v.StringRule("language", "in:it,en")
178 v.StringRule("role", "in:user,admin")
179
180 if !v.Validate() {
181 return ctx.Status(422).JSON(v.Errors)
182 }
183 updatedUser, err := userService.Update(ctx.Params("id"), me.AccountID, inputMap)
184 if err != nil {
185 return ctx.Status(404).JSON(fiber.Map{
186 "message": err.Error(),
187 })
188 }
189 showUser := models.ShowUserSerializer().Transform(updatedUser)
190 return ctx.JSON(showUser)
191}
192
193// Delete function
194func (userEndpoint *UserEndpoint) Delete(ctx *fiber.Ctx) error {

Callers 2

UpdateMeMethod · 0.45
GenerateSsoMethod · 0.45

Calls 3

ShowUserSerializerFunction · 0.92
CurrentUserMethod · 0.80
CanMethod · 0.80

Tested by

no test coverage detected