feat: add content review flow

This commit is contained in:
2026-01-15 11:10:43 +08:00
parent 37da8256fa
commit 37325ab1b4
10 changed files with 422 additions and 4 deletions

View File

@@ -86,3 +86,19 @@ func (c *contents) UpdateStatus(ctx fiber.Ctx, tenantID, contentID int64, form *
func (c *contents) Review(ctx fiber.Ctx, user *models.User, id int64, form *dto.SuperContentReviewForm) error {
return services.Super.ReviewContent(ctx, user.ID, id, form)
}
// Batch review contents
//
// @Router /super/v1/contents/review/batch [post]
// @Summary Batch review contents
// @Description Batch review contents
// @Tags Content
// @Accept json
// @Produce json
// @Param form body dto.SuperContentBatchReviewForm true "Batch review form"
// @Success 200 {string} string "Reviewed"
// @Bind user local key(__ctx_user)
// @Bind form body
func (c *contents) BatchReview(ctx fiber.Ctx, user *models.User, form *dto.SuperContentBatchReviewForm) error {
return services.Super.BatchReviewContents(ctx, user.ID, form)
}

View File

@@ -391,6 +391,15 @@ type SuperContentReviewForm struct {
Reason string `json:"reason"`
}
type SuperContentBatchReviewForm struct {
// ContentIDs 待审核内容ID列表。
ContentIDs []int64 `json:"content_ids" validate:"required,min=1,dive,gt=0"`
// Action 审核动作approve/reject
Action string `json:"action" validate:"required,oneof=approve reject"`
// Reason 审核说明(驳回时填写,便于作者修正)。
Reason string `json:"reason"`
}
type SuperTenantUserItem struct {
// User 用户信息。
User *SuperUserLite `json:"user"`

View File

@@ -75,6 +75,12 @@ func (r *Routes) Register(router fiber.Router) {
PathParam[int64]("id"),
Body[dto.SuperContentReviewForm]("form"),
))
r.log.Debugf("Registering route: Post /super/v1/contents/review/batch -> contents.BatchReview")
router.Post("/super/v1/contents/review/batch"[len(r.Path()):], Func2(
r.contents.BatchReview,
Local[*models.User]("__ctx_user"),
Body[dto.SuperContentBatchReviewForm]("form"),
))
// Register routes for controller: coupons
r.log.Debugf("Registering route: Get /super/v1/coupons -> coupons.List")
router.Get("/super/v1/coupons"[len(r.Path()):], DataFunc1(

View File

@@ -1061,6 +1061,97 @@ func (s *super) ReviewContent(ctx context.Context, operatorID, contentID int64,
return nil
}
func (s *super) BatchReviewContents(ctx context.Context, operatorID int64, form *super_dto.SuperContentBatchReviewForm) error {
if operatorID == 0 {
return errorx.ErrUnauthorized.WithMsg("缺少操作者信息")
}
if form == nil {
return errorx.ErrBadRequest.WithMsg("审核参数不能为空")
}
action := strings.ToLower(strings.TrimSpace(form.Action))
if action != "approve" && action != "reject" {
return errorx.ErrBadRequest.WithMsg("审核动作非法")
}
// 去重并过滤非法ID确保审核集合有效。
unique := make(map[int64]struct{})
contentIDs := make([]int64, 0, len(form.ContentIDs))
for _, id := range form.ContentIDs {
if id <= 0 {
continue
}
if _, ok := unique[id]; ok {
continue
}
unique[id] = struct{}{}
contentIDs = append(contentIDs, id)
}
if len(contentIDs) == 0 {
return errorx.ErrBadRequest.WithMsg("内容ID不能为空")
}
// 审核动作映射为内容状态。
nextStatus := consts.ContentStatusBlocked
if action == "approve" {
nextStatus = consts.ContentStatusPublished
}
reason := strings.TrimSpace(form.Reason)
var contents []*models.Content
err := models.Q.Transaction(func(tx *models.Query) error {
tbl, q := tx.Content.QueryContext(ctx)
list, err := q.Where(tbl.ID.In(contentIDs...)).Find()
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
if len(list) != len(contentIDs) {
return errorx.ErrRecordNotFound.WithMsg("部分内容不存在")
}
for _, content := range list {
if content.Status != consts.ContentStatusReviewing {
return errorx.ErrStatusConflict.WithMsg("仅可审核待审核内容")
}
}
updates := &models.Content{
Status: nextStatus,
UpdatedAt: time.Now(),
}
if nextStatus == consts.ContentStatusPublished {
updates.PublishedAt = time.Now()
}
if _, err := q.Where(tbl.ID.In(contentIDs...)).Updates(updates); err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
contents = list
return nil
})
if err != nil {
return err
}
// 审核完成后通知作者并记录审计日志(批量逐条记录,便于追溯)。
title := "内容审核结果"
detail := "内容审核通过"
if action == "reject" {
detail = "内容审核驳回"
if reason != "" {
detail += ",原因:" + reason
}
}
for _, content := range contents {
if Notification != nil {
_ = Notification.Send(ctx, content.TenantID, content.UserID, string(consts.NotificationTypeAudit), title, detail)
}
if Audit != nil {
Audit.Log(ctx, operatorID, "review_content", cast.ToString(content.ID), detail)
}
}
return nil
}
func (s *super) ListOrders(ctx context.Context, filter *super_dto.SuperOrderListFilter) (*requests.Pager, error) {
tbl, q := models.OrderQuery.QueryContext(ctx)

View File

@@ -133,6 +133,40 @@ const docTemplate = `{
}
}
},
"/super/v1/contents/review/batch": {
"post": {
"description": "Batch review contents",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Content"
],
"summary": "Batch review contents",
"parameters": [
{
"description": "Batch review form",
"name": "form",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.SuperContentBatchReviewForm"
}
}
],
"responses": {
"200": {
"description": "Reviewed",
"schema": {
"type": "string"
}
}
}
}
},
"/super/v1/contents/{id}/review": {
"post": {
"description": "Review content",
@@ -5502,6 +5536,35 @@ const docTemplate = `{
}
}
},
"dto.SuperContentBatchReviewForm": {
"type": "object",
"required": [
"action",
"content_ids"
],
"properties": {
"action": {
"description": "Action 审核动作approve/reject。",
"type": "string",
"enum": [
"approve",
"reject"
]
},
"content_ids": {
"description": "ContentIDs 待审核内容ID列表。",
"type": "array",
"minItems": 1,
"items": {
"type": "integer"
}
},
"reason": {
"description": "Reason 审核说明(驳回时填写,便于作者修正)。",
"type": "string"
}
}
},
"dto.SuperContentReviewForm": {
"type": "object",
"required": [

View File

@@ -127,6 +127,40 @@
}
}
},
"/super/v1/contents/review/batch": {
"post": {
"description": "Batch review contents",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Content"
],
"summary": "Batch review contents",
"parameters": [
{
"description": "Batch review form",
"name": "form",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.SuperContentBatchReviewForm"
}
}
],
"responses": {
"200": {
"description": "Reviewed",
"schema": {
"type": "string"
}
}
}
}
},
"/super/v1/contents/{id}/review": {
"post": {
"description": "Review content",
@@ -5496,6 +5530,35 @@
}
}
},
"dto.SuperContentBatchReviewForm": {
"type": "object",
"required": [
"action",
"content_ids"
],
"properties": {
"action": {
"description": "Action 审核动作approve/reject。",
"type": "string",
"enum": [
"approve",
"reject"
]
},
"content_ids": {
"description": "ContentIDs 待审核内容ID列表。",
"type": "array",
"minItems": 1,
"items": {
"type": "integer"
}
},
"reason": {
"description": "Reason 审核说明(驳回时填写,便于作者修正)。",
"type": "string"
}
}
},
"dto.SuperContentReviewForm": {
"type": "object",
"required": [

View File

@@ -1003,6 +1003,27 @@ definitions:
description: Likes 累计点赞数。
type: integer
type: object
dto.SuperContentBatchReviewForm:
properties:
action:
description: Action 审核动作approve/reject
enum:
- approve
- reject
type: string
content_ids:
description: ContentIDs 待审核内容ID列表。
items:
type: integer
minItems: 1
type: array
reason:
description: Reason 审核说明(驳回时填写,便于作者修正)。
type: string
required:
- action
- content_ids
type: object
dto.SuperContentReviewForm:
properties:
action:
@@ -2138,6 +2159,28 @@ paths:
summary: Review content
tags:
- Content
/super/v1/contents/review/batch:
post:
consumes:
- application/json
description: Batch review contents
parameters:
- description: Batch review form
in: body
name: form
required: true
schema:
$ref: '#/definitions/dto.SuperContentBatchReviewForm'
produces:
- application/json
responses:
"200":
description: Reviewed
schema:
type: string
summary: Batch review contents
tags:
- Content
/super/v1/coupons:
get:
consumes: