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

Method getProduct

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

Source from the content-addressed store, hash-verified

48}
49
50func (h *handler) getProduct(w http.ResponseWriter, r *http.Request) {
51 id := chi.URLParam(r, "id")
52 i, err := strconv.ParseInt(id, 10, 64)
53 if err != nil {
54 http.Error(w, "error parsing ID", http.StatusBadRequest)
55 return
56 }
57
58 product, err := h.client.GetProduct(h.ctx, &pb.ProductReq{Id: i})
59 if err != nil {
60 http.Error(w, "error getting product", http.StatusInternalServerError)
61 return
62 }
63
64 res := toProductRes(product)
65 w.Header().Set("Content-Type", "application/json")
66 w.WriteHeader(http.StatusOK)
67 json.NewEncoder(w).Encode(res)
68}
69
70func (h *handler) listProducts(w http.ResponseWriter, r *http.Request) {
71 lpr, err := h.client.ListProducts(h.ctx, &pb.ProductReq{})

Callers

nothing calls this directly

Calls 2

toProductResFunction · 0.85
GetProductMethod · 0.65

Tested by

no test coverage detected