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

Method Update

endpoints/account.endpoint.go:25–55  ·  view source on GitHub ↗

Update function

(ctx *fiber.Ctx)

Source from the content-addressed store, hash-verified

23
24// Update function
25func (accountEndpoint *AccountEndpoint) Update(ctx *fiber.Ctx) error {
26 if can := userEndpoint.Can(ctx, models.AdminRole); !can {
27 return ctx.Status(401).JSON(fiber.Map{
28 "message": "You are not authorized to perform this action",
29 })
30 }
31
32 var inputMap = make(map[string]interface{})
33 ctx.BodyParser(&inputMap)
34
35 v := validate.Map(inputMap)
36 v.StringRule("companyName", "ascii")
37 v.StringRule("companyVat", "ascii")
38 v.StringRule("companyBillingAddress", "ascii")
39 v.StringRule("companySdi", "ascii")
40 v.StringRule("companyEmail", "email")
41 v.StringRule("companyPec", "email")
42 v.StringRule("companyCountry", "ascii")
43
44 if !v.Validate() {
45 return ctx.Status(422).JSON(v.Errors)
46 }
47 updatedAccount, err := accountService.Update(ctx.Params("id"), inputMap)
48 if err != nil {
49 return ctx.Status(404).JSON(fiber.Map{
50 "message": err.Error(),
51 })
52 }
53 showAccount := models.ShowAccountSerializer().Transform(updatedAccount)
54 return ctx.JSON(showAccount)
55}

Callers

nothing calls this directly

Calls 2

ShowAccountSerializerFunction · 0.92
CanMethod · 0.80

Tested by

no test coverage detected