Create function
(ctx *fiber.Ctx)
| 128 | |
| 129 | // Create function |
| 130 | func (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 |
| 163 | func (userEndpoint *UserEndpoint) Update(ctx *fiber.Ctx) error { |
nothing calls this directly
no test coverage detected