fix: 修复养成管理接口参数过滤

This commit is contained in:
richjohnrambo
2026-09-20 16:53:38 +08:00
parent 47ed097923
commit 6bf364ec0b
2 changed files with 28 additions and 4 deletions
+25 -4
View File
@@ -71,6 +71,9 @@ func (s *sSysCultivateContent) Dashboard(ctx context.Context, _ *sysin.Cultivate
}
func (s *sSysCultivateContent) List(ctx context.Context, in *sysin.CultivateContentListInp) (list []*sysin.CultivateContentListModel, totalCount int, err error) {
if err = in.Filter(ctx); err != nil {
return nil, 0, err
}
tenantID := cultivateTenantID(ctx)
if in.ObjectType == "feed_comment" {
columns := dao.FeedComment.Columns()
@@ -125,12 +128,15 @@ func (s *sSysCultivateContent) List(ctx context.Context, in *sysin.CultivateCont
}
func (s *sSysCultivateContent) View(ctx context.Context, in *sysin.CultivateContentViewInp) (*sysin.CultivateContentViewModel, error) {
if err := in.Filter(ctx); err != nil {
return nil, err
}
tenantID := cultivateTenantID(ctx)
base := &sysin.CultivateContentViewModel{Media: []*sysin.CultivateMediaModel{}, Audits: []*sysin.CultivateAuditModel{}, RelatedReports: []*sysin.CultivateReportListModel{}}
if in.ObjectType == "feed_comment" {
c := dao.FeedComment.Columns()
var row entity.FeedComment
if err := dao.FeedComment.Ctx(ctx).Where(g.Map{c.Id: in.ObjectId, c.TenantId: tenantID}).Scan(&row); err != nil {
if err := dao.FeedComment.Ctx(ctx).Where(g.Map{c.Id: in.ObjectId, c.TenantId: tenantID}).Scan(&row); err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
if row.Id == 0 {
@@ -140,7 +146,7 @@ func (s *sSysCultivateContent) View(ctx context.Context, in *sysin.CultivateCont
} else {
c := dao.FeedPost.Columns()
var row entity.FeedPost
if err := dao.FeedPost.Ctx(ctx).Where(g.Map{c.Id: in.ObjectId, c.TenantId: tenantID}).Scan(&row); err != nil {
if err := dao.FeedPost.Ctx(ctx).Where(g.Map{c.Id: in.ObjectId, c.TenantId: tenantID}).Scan(&row); err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
if row.Id == 0 {
@@ -149,7 +155,7 @@ func (s *sSysCultivateContent) View(ctx context.Context, in *sysin.CultivateCont
base.CultivateContentListModel = sysin.CultivateContentListModel{Id: in.Id, ObjectType: in.ObjectType, AuthorId: strconv.FormatUint(row.AuthorId, 10), ContentText: row.ContentText, FlowerCode: row.FlowerCode, Visibility: row.Visibility, Status: row.Status, AuditStatus: row.AuditStatus, RejectReason: row.RejectReasonCode, LikeCount: row.LikeCount, CommentCount: row.CommentCount, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt}
mc := dao.FeedMedia.Columns()
var media []*entity.FeedMedia
if err := dao.FeedMedia.Ctx(ctx).Where(g.Map{mc.TenantId: tenantID, mc.PostId: in.ObjectId}).OrderAsc(mc.SortNo).Scan(&media); err != nil {
if err := dao.FeedMedia.Ctx(ctx).Where(g.Map{mc.TenantId: tenantID, mc.PostId: in.ObjectId}).OrderAsc(mc.SortNo).Scan(&media); err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
for _, m := range media {
@@ -158,7 +164,7 @@ func (s *sSysCultivateContent) View(ctx context.Context, in *sysin.CultivateCont
}
ac := dao.ContentAuditLog.Columns()
var audits []*entity.ContentAuditLog
if err := dao.ContentAuditLog.Ctx(ctx).Where(g.Map{ac.TenantId: tenantID, ac.ObjectType: in.ObjectType, ac.ObjectId: in.ObjectId}).OrderDesc(ac.Id).Scan(&audits); err != nil {
if err := dao.ContentAuditLog.Ctx(ctx).Where(g.Map{ac.TenantId: tenantID, ac.ObjectType: in.ObjectType, ac.ObjectId: in.ObjectId}).OrderDesc(ac.Id).Scan(&audits); err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
for _, a := range audits {
@@ -180,6 +186,9 @@ func (s *sSysCultivateContent) View(ctx context.Context, in *sysin.CultivateCont
}
func (s *sSysCultivateContent) Review(ctx context.Context, in *sysin.CultivateContentReviewInp) error {
if err := in.Filter(ctx); err != nil {
return err
}
tenantID, operatorID := cultivateTenantID(ctx), contexts.GetUserId(ctx)
var authorID uint64
err := dao.FeedPost.Transaction(ctx, func(txCtx context.Context, tx gdb.TX) error {
@@ -210,6 +219,9 @@ func (s *sSysCultivateContent) Review(ctx context.Context, in *sysin.CultivateCo
}
func (s *sSysCultivateContent) BatchReview(ctx context.Context, in *sysin.CultivateContentBatchReviewInp) (*sysin.CultivateContentBatchReviewModel, error) {
if err := in.Filter(ctx); err != nil {
return nil, err
}
result := &sysin.CultivateContentBatchReviewModel{Failures: make(map[string]string)}
for _, id := range in.Ids {
item := &sysin.CultivateContentReviewInp{ObjectType: in.ObjectType, Id: id, Action: in.Action, Reason: in.Reason}
@@ -367,6 +379,9 @@ func writeContentAudit(ctx context.Context, tx gdb.TX, tenantID, operatorID int6
}
func (s *sSysCultivateContent) ReportList(ctx context.Context, in *sysin.CultivateReportListInp) (list []*sysin.CultivateReportListModel, totalCount int, err error) {
if err = in.Filter(ctx); err != nil {
return nil, 0, err
}
columns := dao.FeedReport.Columns()
mod := dao.FeedReport.Ctx(ctx).Where(columns.TenantId, cultivateTenantID(ctx))
if in.ObjectType != "" {
@@ -397,6 +412,9 @@ func reportModel(row *entity.FeedReport) *sysin.CultivateReportListModel {
}
func (s *sSysCultivateContent) ReportView(ctx context.Context, in *sysin.CultivateReportViewInp) (*sysin.CultivateReportViewModel, error) {
if err := in.Filter(ctx); err != nil {
return nil, err
}
tenantID := cultivateTenantID(ctx)
c := dao.FeedReport.Columns()
var row entity.FeedReport
@@ -430,6 +448,9 @@ func (s *sSysCultivateContent) ReportView(ctx context.Context, in *sysin.Cultiva
}
func (s *sSysCultivateContent) ReportHandle(ctx context.Context, in *sysin.CultivateReportHandleInp) error {
if err := in.Filter(ctx); err != nil {
return err
}
tenantID, operatorID := cultivateTenantID(ctx), contexts.GetUserId(ctx)
columns := dao.FeedReport.Columns()
var report entity.FeedReport
@@ -89,6 +89,9 @@ func (s *sSysCultivateFlower) View(ctx context.Context, in *sysin.CultivateFlowe
}
func (s *sSysCultivateFlower) Edit(ctx context.Context, in *sysin.CultivateFlowerEditInp) (err error) {
if err = in.Filter(ctx); err != nil {
return err
}
tenantID := cultivateTenantID(ctx)
if err = validateCultivateAssets(ctx, tenantID, in); err != nil {
return err