HandleCreate returns an http.HandlerFunc that processes an http.Request to create the named user account in the system.
(userCtrl *user.Controller)
| 26 | // HandleCreate returns an http.HandlerFunc that processes an http.Request |
| 27 | // to create the named user account in the system. |
| 28 | func HandleCreate(userCtrl *user.Controller) http.HandlerFunc { |
| 29 | return func(w http.ResponseWriter, r *http.Request) { |
| 30 | ctx := r.Context() |
| 31 | session, _ := request.AuthSessionFrom(ctx) |
| 32 | |
| 33 | in := new(user.CreateInput) |
| 34 | err := json.NewDecoder(r.Body).Decode(in) |
| 35 | if err != nil { |
| 36 | render.BadRequestf(ctx, w, "Invalid request body: %s.", err) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | usr, err := userCtrl.Create(ctx, session, in) |
| 41 | if err != nil { |
| 42 | render.TranslatedUserError(ctx, w, err) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | render.JSON(w, http.StatusCreated, usr) |
| 47 | } |
| 48 | } |
no test coverage detected
searching dependent graphs…