MCPcopy Index your code
hub / github.com/53AI/53AIHub / UpdateOrderStatus

Function UpdateOrderStatus

api/controller/order.go:269–322  ·  view source on GitHub ↗

UpdateOrderStatus updates the status of an order @Summary Update order status @Description Update the status of an order @Tags Order @Accept json @Produce json @Security BearerAuth @Param id path int true "Order ID" @Param status body UpdateOrderStatusRequest true "Order status" @Success 200 {object

(c *gin.Context)

Source from the content-addressed store, hash-verified

267// @Success 200 {object} model.CommonResponse{data=model.Order}
268// @Router /api/orders/{id}/status [patch]
269func UpdateOrderStatus(c *gin.Context) {
270 id, err := strconv.ParseInt(c.Param("id"), 10, 64)
271 if err != nil {
272 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Invalid ID"))
273 return
274 }
275
276 eid := config.GetEID(c)
277
278 // Get order
279 order, err := model.GetOrderByID(eid, id)
280 if err != nil {
281 c.JSON(http.StatusNotFound, model.NotFound.ToNewErrorResponse(model.OrderNotFound))
282 return
283 }
284
285 // Check payment type, only manual payment orders can be updated through this interface
286 if order.PayType != 2 {
287 c.JSON(http.StatusBadRequest, model.ParamError.ToNewErrorResponse("Only manual payment orders can be updated through this interface"))
288 return
289 }
290
291 var req UpdateOrderStatusRequest
292 if err := c.ShouldBindJSON(&req); err != nil {
293 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err))
294 return
295 }
296
297 if order.Status != model.OrderStatusConfirming {
298 c.JSON(http.StatusBadRequest, model.ParamError.ToNewErrorResponse("Only orders in confirming status can be updated"))
299 return
300 }
301
302 // Validate status
303 if req.Status < 0 || req.Status > 4 {
304 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse("Invalid status"))
305 return
306 }
307
308 // Update status
309 order.Status = req.Status
310
311 // If status is paid, set paid time
312 if req.Status == model.OrderStatusPaid && order.PayTime == 0 {
313 order.PayTime = time.Now().UTC().UnixMilli()
314 }
315
316 if err := order.Update(); err != nil {
317 c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err))
318 return
319 }
320
321 c.JSON(http.StatusOK, model.Success.ToResponse(order))
322}
323
324// DeleteOrder deletes an order
325// @Summary Delete order

Callers

nothing calls this directly

Calls 4

ToResponseMethod · 0.80
GetEIDMethod · 0.80
ToNewErrorResponseMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected