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

Method createOrder

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

Source from the content-addressed store, hash-verified

129}
130
131func (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
155func (h *handler) getOrder(w http.ResponseWriter, r *http.Request) {
156 claims := r.Context().Value(authKey{}).(*token.UserClaims)

Callers

nothing calls this directly

Calls 3

toPBOrderReqFunction · 0.85
toOrderResFunction · 0.85
CreateOrderMethod · 0.65

Tested by

no test coverage detected