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

Method updateProduct

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

Source from the content-addressed store, hash-verified

85}
86
87func (h *handler) updateProduct(w http.ResponseWriter, r *http.Request) {
88 id := chi.URLParam(r, "id")
89 i, err := strconv.ParseInt(id, 10, 64)
90 if err != nil {
91 http.Error(w, "error parsing ID", http.StatusBadRequest)
92 return
93 }
94
95 var p ProductReq
96 if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
97 http.Error(w, "error decoding request body", http.StatusBadRequest)
98 return
99 }
100 p.ID = i
101
102 updated, err := h.client.UpdateProduct(h.ctx, toPBProductReq(p))
103 if err != nil {
104 http.Error(w, "error updating product", http.StatusInternalServerError)
105 return
106 }
107
108 res := toProductRes(updated)
109 w.Header().Set("Content-Type", "application/json")
110 w.WriteHeader(http.StatusOK)
111 json.NewEncoder(w).Encode(res)
112}
113
114func (h *handler) deleteProduct(w http.ResponseWriter, r *http.Request) {
115 id := chi.URLParam(r, "id")

Callers

nothing calls this directly

Calls 3

toPBProductReqFunction · 0.85
toProductResFunction · 0.85
UpdateProductMethod · 0.65

Tested by

no test coverage detected