(w http.ResponseWriter, r *http.Request)
| 29 | } |
| 30 | |
| 31 | func (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 | |
| 50 | func (h *handler) getProduct(w http.ResponseWriter, r *http.Request) { |
| 51 | id := chi.URLParam(r, "id") |
nothing calls this directly
no test coverage detected