继续补齐核心模块 Context 超时控制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package listing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
@@ -117,7 +118,7 @@ func (h *Handler) SubmitReview(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Handler) ListPendingReview(c *gin.Context) {
|
||||
items, err := h.service.ListPendingReview()
|
||||
items, err := h.service.ListPendingReview(c.Request.Context())
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -130,7 +131,7 @@ func (h *Handler) ListAdmin(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
result, err := h.service.ListAdmin(query)
|
||||
result, err := h.service.ListAdmin(c.Request.Context(), query)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -143,7 +144,7 @@ func (h *Handler) FindAdmin(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.FindAdmin(id)
|
||||
item, err := h.service.FindAdmin(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -159,7 +160,7 @@ func (h *Handler) AdminMarkAbnormal(c *gin.Context) {
|
||||
h.adminAction(c, h.service.AdminMarkAbnormal)
|
||||
}
|
||||
|
||||
func (h *Handler) adminAction(c *gin.Context, fn func(uint64, uint64, AdminActionRequest, AuditMeta) (*ListingDTO, error)) {
|
||||
func (h *Handler) adminAction(c *gin.Context, fn func(context.Context, uint64, uint64, AdminActionRequest, AuditMeta) (*ListingDTO, error)) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少管理员上下文")
|
||||
@@ -174,7 +175,7 @@ func (h *Handler) adminAction(c *gin.Context, fn func(uint64, uint64, AdminActio
|
||||
response.BadRequest(c, "操作原因不能为空")
|
||||
return
|
||||
}
|
||||
item, err := fn(adminID, id, req, auditMeta(c))
|
||||
item, err := fn(c.Request.Context(), adminID, id, req, auditMeta(c))
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -195,7 +196,7 @@ func (h *Handler) Approve(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.Approve(id)
|
||||
item, err := h.service.Approve(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -218,7 +219,7 @@ func (h *Handler) AdjustReviewPrice(c *gin.Context) {
|
||||
response.BadRequest(c, "调价参数不正确")
|
||||
return
|
||||
}
|
||||
item, err := h.service.AdjustReviewPrice(adminID, id, req, auditMeta(c))
|
||||
item, err := h.service.AdjustReviewPrice(c.Request.Context(), adminID, id, req, auditMeta(c))
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -236,7 +237,7 @@ func (h *Handler) Reject(c *gin.Context) {
|
||||
response.BadRequest(c, "审核拒绝原因不能为空")
|
||||
return
|
||||
}
|
||||
item, err := h.service.Reject(id, req)
|
||||
item, err := h.service.Reject(c.Request.Context(), id, req)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -254,7 +255,7 @@ func (h *Handler) Offline(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.Offline(ownerID, id)
|
||||
item, err := h.service.Offline(c.Request.Context(), ownerID, id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -263,7 +264,7 @@ func (h *Handler) Offline(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Handler) ListPublic(c *gin.Context) {
|
||||
items, err := h.service.ListPublic(parsePublicListQuery(c))
|
||||
items, err := h.service.ListPublic(c.Request.Context(), parsePublicListQuery(c))
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -276,7 +277,7 @@ func (h *Handler) FindPublic(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.FindPublic(id)
|
||||
item, err := h.service.FindPublic(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -289,7 +290,7 @@ func (h *Handler) Cover(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
key, err := h.service.FindPublicCoverKey(id)
|
||||
key, err := h.service.FindPublicCoverKey(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -307,7 +308,7 @@ func (h *Handler) Screenshot(c *gin.Context) {
|
||||
response.BadRequest(c, "截图序号不正确")
|
||||
return
|
||||
}
|
||||
key, err := h.service.FindPublicScreenshotKey(id, index)
|
||||
key, err := h.service.FindPublicScreenshotKey(c.Request.Context(), id, index)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -350,7 +351,7 @@ func (h *Handler) ListMine(c *gin.Context) {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
items, err := h.service.ListMine(ownerID)
|
||||
items, err := h.service.ListMine(c.Request.Context(), ownerID)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
@@ -368,7 +369,7 @@ func (h *Handler) FindMine(c *gin.Context) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
item, err := h.service.FindMine(ownerID, id)
|
||||
item, err := h.service.FindMine(c.Request.Context(), ownerID, id)
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user