(w http.ResponseWriter, r *http.Request)
| 129 | } |
| 130 | |
| 131 | func (h *handler) createOrder(w http.ResponseWriter, r *http.Request) { |
| 132 | var o OrderReq |
| 133 | if err := json.NewDecoder(r.Body).Decode(&o); err != nil { |
| 134 | http.Error(w, "bad request", http.StatusBadRequest) |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | claims := r.Context().Value(authKey{}).(*token.UserClaims) |
| 139 | po := toPBOrderReq(o) |
| 140 | po.UserId = claims.ID |
| 141 | po.UserEmail = claims.Email |
| 142 | |
| 143 | created, err := h.client.CreateOrder(h.ctx, po) |
| 144 | if err != nil { |
| 145 | http.Error(w, "internal server error", http.StatusInternalServerError) |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | res := toOrderRes(created) |
| 150 | w.Header().Set("Content-Type", "application/json") |
| 151 | w.WriteHeader(http.StatusCreated) |
| 152 | json.NewEncoder(w).Encode(res) |
| 153 | } |
| 154 | |
| 155 | func (h *handler) getOrder(w http.ResponseWriter, r *http.Request) { |
| 156 | claims := r.Context().Value(authKey{}).(*token.UserClaims) |
nothing calls this directly
no test coverage detected