feat: 完善养成管理后台功能
This commit is contained in:
@@ -50,6 +50,48 @@ type CultivateContentListModel struct {
|
||||
UpdatedAt *gtime.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type CultivateContentViewInp struct {
|
||||
ObjectType string `json:"objectType" v:"required|in:feed_post,feed_comment#内容类型不能为空|内容类型不正确"`
|
||||
Id string `json:"id" v:"required#内容ID不能为空"`
|
||||
ObjectId uint64 `json:"-"`
|
||||
}
|
||||
|
||||
func (in *CultivateContentViewInp) Filter(context.Context) error {
|
||||
id, err := strconv.ParseUint(strings.TrimSpace(in.Id), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
return gerror.New("内容ID不正确")
|
||||
}
|
||||
in.ObjectId = id
|
||||
return nil
|
||||
}
|
||||
|
||||
type CultivateMediaModel struct {
|
||||
Id string `json:"id"`
|
||||
FileId string `json:"fileId"`
|
||||
ThumbnailFileId string `json:"thumbnailFileId"`
|
||||
MediaType string `json:"mediaType"`
|
||||
AuditStatus string `json:"auditStatus"`
|
||||
SortNo uint `json:"sortNo"`
|
||||
}
|
||||
type CultivateAuditModel struct {
|
||||
Id string `json:"id"`
|
||||
AuditSource string `json:"auditSource"`
|
||||
StatusBefore string `json:"statusBefore"`
|
||||
StatusAfter string `json:"statusAfter"`
|
||||
ResultCode string `json:"resultCode"`
|
||||
RiskLabels any `json:"riskLabels"`
|
||||
OperatorId string `json:"operatorId"`
|
||||
OccurredAt *gtime.Time `json:"occurredAt"`
|
||||
}
|
||||
type CultivateContentViewModel struct {
|
||||
CultivateContentListModel
|
||||
AuthorNickname string `json:"authorNickname"`
|
||||
AuthorAvatarFileId string `json:"authorAvatarFileId"`
|
||||
Media []*CultivateMediaModel `json:"media"`
|
||||
Audits []*CultivateAuditModel `json:"audits"`
|
||||
RelatedReports []*CultivateReportListModel `json:"relatedReports"`
|
||||
}
|
||||
|
||||
type CultivateContentReviewInp struct {
|
||||
ObjectType string `json:"objectType" v:"required|in:feed_post,feed_comment#内容类型不能为空|内容类型不正确"`
|
||||
Id string `json:"id" v:"required#内容ID不能为空"`
|
||||
@@ -58,6 +100,36 @@ type CultivateContentReviewInp struct {
|
||||
ObjectId uint64 `json:"-"`
|
||||
}
|
||||
|
||||
type CultivateContentBatchReviewInp struct {
|
||||
ObjectType string `json:"objectType" v:"required|in:feed_post,feed_comment#内容类型不能为空|内容类型不正确"`
|
||||
Ids []string `json:"ids" v:"required#请选择内容"`
|
||||
Action string `json:"action" v:"required|in:approve,reject,take_down,restore#审核动作不能为空|审核动作不正确"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
func (in *CultivateContentBatchReviewInp) Filter(ctx context.Context) error {
|
||||
if len(in.Ids) == 0 || len(in.Ids) > 100 {
|
||||
return gerror.New("单次批量处理数量必须为1至100条")
|
||||
}
|
||||
in.Reason = strings.TrimSpace(in.Reason)
|
||||
if (in.Action == "reject" || in.Action == "take_down") && in.Reason == "" {
|
||||
return gerror.New("拒绝或下架时必须填写原因")
|
||||
}
|
||||
for _, id := range in.Ids {
|
||||
item := &CultivateContentReviewInp{ObjectType: in.ObjectType, Id: id, Action: in.Action, Reason: in.Reason}
|
||||
if err := item.Filter(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CultivateContentBatchReviewModel struct {
|
||||
SuccessCount int `json:"successCount"`
|
||||
FailedCount int `json:"failedCount"`
|
||||
Failures map[string]string `json:"failures"`
|
||||
}
|
||||
|
||||
func (in *CultivateContentReviewInp) Filter(context.Context) error {
|
||||
id, err := strconv.ParseUint(strings.TrimSpace(in.Id), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
@@ -105,11 +177,36 @@ type CultivateReportListModel struct {
|
||||
CreatedAt *gtime.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type CultivateReportViewInp struct {
|
||||
Id string `json:"id" v:"required#举报ID不能为空"`
|
||||
ReportId uint64 `json:"-"`
|
||||
}
|
||||
|
||||
func (in *CultivateReportViewInp) Filter(context.Context) error {
|
||||
id, err := strconv.ParseUint(strings.TrimSpace(in.Id), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
return gerror.New("举报ID不正确")
|
||||
}
|
||||
in.ReportId = id
|
||||
return nil
|
||||
}
|
||||
|
||||
type CultivateReportViewModel struct {
|
||||
CultivateReportListModel
|
||||
ReporterNickname string `json:"reporterNickname"`
|
||||
ReportedUserNickname string `json:"reportedUserNickname"`
|
||||
TargetContent *CultivateContentListModel `json:"targetContent"`
|
||||
History []*CultivateReportListModel `json:"history"`
|
||||
}
|
||||
|
||||
type CultivateReportHandleInp struct {
|
||||
Id string `json:"id" v:"required#举报ID不能为空"`
|
||||
Action string `json:"action" v:"required|in:processing,resolve,reject#处理动作不能为空|处理动作不正确"`
|
||||
HandleResult string `json:"handleResult"`
|
||||
ReportId uint64 `json:"-"`
|
||||
Id string `json:"id" v:"required#举报ID不能为空"`
|
||||
Action string `json:"action" v:"required|in:processing,resolve,reject#处理动作不能为空|处理动作不正确"`
|
||||
HandleResult string `json:"handleResult"`
|
||||
ContentAction string `json:"contentAction" v:"in:none,take_down#内容处置不正确"`
|
||||
UserAction string `json:"userAction" v:"in:none,freeze,ban#用户处置不正确"`
|
||||
Reason string `json:"reason"`
|
||||
ReportId uint64 `json:"-"`
|
||||
}
|
||||
|
||||
func (in *CultivateReportHandleInp) Filter(context.Context) error {
|
||||
@@ -119,9 +216,24 @@ func (in *CultivateReportHandleInp) Filter(context.Context) error {
|
||||
}
|
||||
in.ReportId = id
|
||||
in.HandleResult = strings.TrimSpace(in.HandleResult)
|
||||
in.ContentAction = strings.TrimSpace(in.ContentAction)
|
||||
in.UserAction = strings.TrimSpace(in.UserAction)
|
||||
in.Reason = strings.TrimSpace(in.Reason)
|
||||
if in.ContentAction == "" {
|
||||
in.ContentAction = "none"
|
||||
}
|
||||
if in.UserAction == "" {
|
||||
in.UserAction = "none"
|
||||
}
|
||||
if in.Action != "processing" && in.HandleResult == "" {
|
||||
return gerror.New("办结举报时必须填写处理结果")
|
||||
}
|
||||
if (in.ContentAction != "none" || in.UserAction != "none") && in.Reason == "" {
|
||||
return gerror.New("联动处置时必须填写处置原因")
|
||||
}
|
||||
if in.Action != "resolve" && (in.ContentAction != "none" || in.UserAction != "none") {
|
||||
return gerror.New("仅确认处理时可执行内容或用户处置")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -130,9 +242,38 @@ type CultivateOperationLogListInp struct {
|
||||
OperatorId string `json:"operatorId"`
|
||||
OperationType string `json:"operationType"`
|
||||
TargetType string `json:"targetType"`
|
||||
TargetId string `json:"targetId"`
|
||||
RequestId string `json:"requestId"`
|
||||
CreatedAt []*gtime.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type CultivateDashboardInp struct{}
|
||||
|
||||
func (*CultivateDashboardInp) Filter(context.Context) error { return nil }
|
||||
|
||||
type CultivateDashboardModel struct {
|
||||
PlantCount int64 `json:"plantCount"`
|
||||
GrowingCount int64 `json:"growingCount"`
|
||||
BloomCount int64 `json:"bloomCount"`
|
||||
HarvestedCount int64 `json:"harvestedCount"`
|
||||
RemovedCount int64 `json:"removedCount"`
|
||||
Active7d int64 `json:"active7d"`
|
||||
Active30d int64 `json:"active30d"`
|
||||
PostCount int64 `json:"postCount"`
|
||||
PublicPostCount int64 `json:"publicPostCount"`
|
||||
FriendsPostCount int64 `json:"friendsPostCount"`
|
||||
PrivatePostCount int64 `json:"privatePostCount"`
|
||||
CommentCount int64 `json:"commentCount"`
|
||||
LikeCount int64 `json:"likeCount"`
|
||||
TakenDownCount int64 `json:"takenDownCount"`
|
||||
PendingAuditCount int64 `json:"pendingAuditCount"`
|
||||
ApprovedAuditCount int64 `json:"approvedAuditCount"`
|
||||
RejectedAuditCount int64 `json:"rejectedAuditCount"`
|
||||
PendingReportCount int64 `json:"pendingReportCount"`
|
||||
ProcessingReportCount int64 `json:"processingReportCount"`
|
||||
ProcessedReportCount int64 `json:"processedReportCount"`
|
||||
}
|
||||
|
||||
func (*CultivateOperationLogListInp) Filter(context.Context) error { return nil }
|
||||
|
||||
type CultivateOperationLogListModel struct {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package sysin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCultivateContentBatchReviewFilter(t *testing.T) {
|
||||
in := &CultivateContentBatchReviewInp{ObjectType: "feed_post", Ids: []string{"123"}, Action: "take_down", Reason: "违规内容"}
|
||||
if err := in.Filter(context.Background()); err != nil {
|
||||
t.Fatalf("Filter returned error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCultivateContentBatchReviewFilterRequiresReason(t *testing.T) {
|
||||
in := &CultivateContentBatchReviewInp{ObjectType: "feed_post", Ids: []string{"123"}, Action: "reject"}
|
||||
if err := in.Filter(context.Background()); err == nil {
|
||||
t.Fatal("expected missing reason error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCultivateReportHandleFilterGovernanceRules(t *testing.T) {
|
||||
in := &CultivateReportHandleInp{Id: "123", Action: "processing", UserAction: "freeze", Reason: "恶意行为"}
|
||||
if err := in.Filter(context.Background()); err == nil {
|
||||
t.Fatal("expected governance action to require resolve")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user