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

Method createProduct

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

Source from the content-addressed store, hash-verified

29}
30
31func (h *handler) createProduct(w http.ResponseWriter, r *http.Request) {
32 var p ProductReq
33 if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
34 http.Error(w, "error decoding request body", http.StatusBadRequest)
35 return
36 }
37
38 product, err := h.client.CreateProduct(h.ctx, toPBProductReq(p))
39 if err != nil {
40 http.Error(w, "error creating product", http.StatusInternalServerError)
41 return
42 }
43
44 res := toProductRes(product)
45 w.Header().Set("Content-Type", "application/json")
46 w.WriteHeader(http.StatusCreated)
47 json.NewEncoder(w).Encode(res)
48}
49
50func (h *handler) getProduct(w http.ResponseWriter, r *http.Request) {
51 id := chi.URLParam(r, "id")

Callers

nothing calls this directly

Calls 3

toPBProductReqFunction · 0.85
toProductResFunction · 0.85
CreateProductMethod · 0.65

Tested by

no test coverage detected