(w http.ResponseWriter, r *http.Request)
| 85 | } |
| 86 | |
| 87 | func (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 | |
| 114 | func (h *handler) deleteProduct(w http.ResponseWriter, r *http.Request) { |
| 115 | id := chi.URLParam(r, "id") |
nothing calls this directly
no test coverage detected