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

Method updateUser

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

Source from the content-addressed store, hash-verified

276}
277
278func (h *handler) updateUser(w http.ResponseWriter, r *http.Request) {
279 var u UserReq
280 if err := json.NewDecoder(r.Body).Decode(&u); err != nil {
281 http.Error(w, "error decoding request body", http.StatusBadRequest)
282 return
283 }
284
285 claims := r.Context().Value(authKey{}).(*token.UserClaims)
286 u.Email = claims.Email
287
288 updated, err := h.client.UpdateUser(h.ctx, toPBUserReq(u))
289 if err != nil {
290 http.Error(w, "error updating user", http.StatusInternalServerError)
291 return
292 }
293
294 res := toUserRes(updated)
295 w.Header().Set("Content-Type", "application/json")
296 w.WriteHeader(http.StatusOK)
297 json.NewEncoder(w).Encode(res)
298}
299
300func (h handler) deleteUser(w http.ResponseWriter, r *http.Request) {
301 id := chi.URLParam(r, "id")

Callers

nothing calls this directly

Calls 3

toPBUserReqFunction · 0.85
toUserResFunction · 0.85
UpdateUserMethod · 0.65

Tested by

no test coverage detected