MCPcopy Create free account
hub / github.com/dhij/ecomm / createUser

Method createUser

ecomm-api/handler/handler.go:235–260  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

233}
234
235func (h *handler) createUser(w http.ResponseWriter, r *http.Request) {
236 var u UserReq
237 if err := json.NewDecoder(r.Body).Decode(&u); err != nil {
238 http.Error(w, "bad request", http.StatusBadRequest)
239 return
240 }
241
242 // hash password
243 hashed, err := util.HashPassword(u.Password)
244 if err != nil {
245 http.Error(w, "error hashing password", http.StatusInternalServerError)
246 return
247 }
248 u.Password = hashed
249
250 created, err := h.client.CreateUser(h.ctx, toPBUserReq(u))
251 if err != nil {
252 http.Error(w, "error creating user", http.StatusInternalServerError)
253 return
254 }
255
256 res := toUserRes(created)
257 w.Header().Set("Content-Type", "application/json")
258 w.WriteHeader(http.StatusCreated)
259 json.NewEncoder(w).Encode(res)
260}
261
262func (h *handler) listUsers(w http.ResponseWriter, r *http.Request) {
263 users, err := h.client.ListUsers(h.ctx, &pb.UserReq{})

Callers

nothing calls this directly

Calls 4

HashPasswordFunction · 0.92
toPBUserReqFunction · 0.85
toUserResFunction · 0.85
CreateUserMethod · 0.65

Tested by

no test coverage detected