继续补齐核心模块 Context 超时控制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -30,7 +31,7 @@ func (h *Handler) Create(c *gin.Context) {
|
||||
response.BadRequest(c, "订单信息不完整")
|
||||
return
|
||||
}
|
||||
item, err := h.service.Create(userID, req)
|
||||
item, err := h.service.Create(c.Request.Context(), userID, req)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -44,7 +45,7 @@ func (h *Handler) List(c *gin.Context) {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
items, err := h.service.ListForUser(userID)
|
||||
items, err := h.service.ListForUser(c.Request.Context(), userID)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -54,7 +55,7 @@ func (h *Handler) List(c *gin.Context) {
|
||||
|
||||
func (h *Handler) AdminList(c *gin.Context) {
|
||||
page, pageSize := parsePagination(c)
|
||||
result, err := h.service.ListAdmin(page, pageSize)
|
||||
result, err := h.service.ListAdmin(c.Request.Context(), page, pageSize)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -67,7 +68,7 @@ func (h *Handler) AdminDetail(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.FindAdmin(id)
|
||||
item, err := h.service.FindAdmin(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -80,7 +81,7 @@ func (h *Handler) AdminHandoffRecords(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
items, err := h.service.HandoffRecordsAdmin(id)
|
||||
items, err := h.service.HandoffRecordsAdmin(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -101,7 +102,7 @@ func (h *Handler) AdminRefund(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.AdminRefund(orderID)
|
||||
item, err := h.service.AdminRefund(c.Request.Context(), orderID)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -114,7 +115,7 @@ func (h *Handler) AdminRefundStatus(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.AdminRefundStatus(orderID)
|
||||
item, err := h.service.AdminRefundStatus(c.Request.Context(), orderID)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -122,7 +123,7 @@ func (h *Handler) AdminRefundStatus(c *gin.Context) {
|
||||
response.OK(c, item)
|
||||
}
|
||||
|
||||
func (h *Handler) adminAction(c *gin.Context, fn func(uint64, uint64, AdminActionRequest, AuditMeta) error, okData gin.H) {
|
||||
func (h *Handler) adminAction(c *gin.Context, fn func(context.Context, uint64, uint64, AdminActionRequest, AuditMeta) error, okData gin.H) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少管理员上下文")
|
||||
@@ -137,7 +138,7 @@ func (h *Handler) adminAction(c *gin.Context, fn func(uint64, uint64, AdminActio
|
||||
response.BadRequest(c, "操作原因不能为空")
|
||||
return
|
||||
}
|
||||
if err := fn(adminID, id, req, auditMeta(c)); err != nil {
|
||||
if err := fn(c.Request.Context(), adminID, id, req, auditMeta(c)); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -162,7 +163,7 @@ func (h *Handler) Detail(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.FindForUser(userID, id)
|
||||
item, err := h.service.FindForUser(c.Request.Context(), userID, id)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -180,7 +181,7 @@ func (h *Handler) Cancel(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.Cancel(userID, id); err != nil {
|
||||
if err := h.service.Cancel(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -197,7 +198,7 @@ func (h *Handler) Pay(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.Pay(userID, id); err != nil {
|
||||
if err := h.service.Pay(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -219,7 +220,7 @@ func (h *Handler) SubmitHandoff(c *gin.Context) {
|
||||
response.BadRequest(c, "交接说明不能为空")
|
||||
return
|
||||
}
|
||||
record, err := h.service.SubmitHandoff(userID, id, req)
|
||||
record, err := h.service.SubmitHandoff(c.Request.Context(), userID, id, req)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -237,7 +238,7 @@ func (h *Handler) ConfirmReceive(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.ConfirmReceive(userID, id); err != nil {
|
||||
if err := h.service.ConfirmReceive(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -254,7 +255,7 @@ func (h *Handler) HandoffRecords(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
items, err := h.service.HandoffRecords(userID, id)
|
||||
items, err := h.service.HandoffRecords(c.Request.Context(), userID, id)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -277,7 +278,7 @@ func (h *Handler) SubmitReturn(c *gin.Context) {
|
||||
response.BadRequest(c, "归还说明不能为空")
|
||||
return
|
||||
}
|
||||
record, err := h.service.SubmitReturn(userID, id, req)
|
||||
record, err := h.service.SubmitReturn(c.Request.Context(), userID, id, req)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -295,7 +296,7 @@ func (h *Handler) ConfirmReturn(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.ConfirmReturn(userID, id); err != nil {
|
||||
if err := h.service.ConfirmReturn(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -317,7 +318,7 @@ func (h *Handler) SubmitCheckout(c *gin.Context) {
|
||||
response.BadRequest(c, "结账说明不能为空")
|
||||
return
|
||||
}
|
||||
record, err := h.service.SubmitCheckout(userID, id, req)
|
||||
record, err := h.service.SubmitCheckout(c.Request.Context(), userID, id, req)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -335,7 +336,7 @@ func (h *Handler) ConfirmCheckout(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.ConfirmCheckout(userID, id); err != nil {
|
||||
if err := h.service.ConfirmCheckout(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -357,7 +358,7 @@ func (h *Handler) CounterCheckout(c *gin.Context) {
|
||||
response.BadRequest(c, "结账修正原因不能为空")
|
||||
return
|
||||
}
|
||||
checkout, err := h.service.CounterCheckout(userID, id, req)
|
||||
checkout, err := h.service.CounterCheckout(c.Request.Context(), userID, id, req)
|
||||
if err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
@@ -375,7 +376,7 @@ func (h *Handler) AcceptCheckout(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.AcceptCheckout(userID, id); err != nil {
|
||||
if err := h.service.AcceptCheckout(c.Request.Context(), userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user