(w http.ResponseWriter, r *http.Request)
| 48 | } |
| 49 | |
| 50 | func (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 | |
| 70 | func (h *handler) listProducts(w http.ResponseWriter, r *http.Request) { |
| 71 | lpr, err := h.client.ListProducts(h.ctx, &pb.ProductReq{}) |
nothing calls this directly
no test coverage detected