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

Method Create

endpoints/user.endpoint.go:130–160  ·  view source on GitHub ↗

Create function

(ctx *fiber.Ctx)

Source from the content-addressed store, hash-verified

128
129// Create function
130func (userEndpoint *UserEndpoint) Create(ctx *fiber.Ctx) error {
131 me, _ := userEndpoint.CurrentUser(ctx)
132 if can := userEndpoint.Can(ctx, models.AdminRole); !can {
133 return ctx.Status(401).JSON(fiber.Map{
134 "message": "You are not authorized to perform this action",
135 })
136 }
137
138 var inputMap = make(map[string]interface{})
139 ctx.BodyParser(&inputMap)
140
141 v := validate.Map(inputMap)
142 v.StringRule("name", "alpha")
143 v.StringRule("surname", "alpha")
144 v.StringRule("language", "in:it,en")
145 v.StringRule("email", "required")
146 v.StringRule("password", "alpha")
147 v.StringRule("role", "in:user,admin")
148
149 if !v.Validate() {
150 return ctx.Status(422).JSON(v.Errors)
151 }
152 user, err := userService.Create(inputMap, me.AccountID)
153 if err != nil {
154 return ctx.Status(422).JSON(fiber.Map{
155 "message": err.Error(),
156 })
157 }
158 showUser := models.ShowUserSerializer().Transform(user)
159 return ctx.JSON(showUser)
160}
161
162// Update function
163func (userEndpoint *UserEndpoint) Update(ctx *fiber.Ctx) error {

Callers

nothing calls this directly

Calls 3

ShowUserSerializerFunction · 0.92
CurrentUserMethod · 0.80
CanMethod · 0.80

Tested by

no test coverage detected