feat(ops): ECR-007 行为分析与 ECR-008 内容运营后台
落地埋点 ingest/数据看板、首页宫格 CMS 与测评上下架;含账号引导、问答流式与免责声明去重,以及 review P1 审计同事务修复。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
||||
homesvc "github.com/yuxingu/digital-psychology/apps/api/internal/service/home"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidScaleStatus = errors.New("invalid scale status")
|
||||
ErrScaleNotFound = errors.New("scale not found")
|
||||
)
|
||||
|
||||
// ListHomeTools returns all grid tools.
|
||||
func (s *Service) ListHomeTools(ctx context.Context) ([]repository.HomeTool, error) {
|
||||
if s.Home == nil {
|
||||
return nil, errors.New("home unavailable")
|
||||
}
|
||||
return s.Home.ListAdmin(ctx)
|
||||
}
|
||||
|
||||
// ReplaceHomeTools replaces grid and audits in one transaction.
|
||||
func (s *Service) ReplaceHomeTools(ctx context.Context, adminID uuid.UUID, items []homesvc.ReplaceInput) error {
|
||||
if s.Home == nil {
|
||||
return errors.New("home unavailable")
|
||||
}
|
||||
meta, _ := json.Marshal(map[string]any{"count": len(items)})
|
||||
return s.Home.ReplaceWithAudit(ctx, adminID, items, meta)
|
||||
}
|
||||
|
||||
// ListScalesAdmin returns all scales.
|
||||
func (s *Service) ListScalesAdmin(ctx context.Context) ([]repository.ScaleAdminItem, error) {
|
||||
if s.Scales == nil {
|
||||
return nil, errors.New("scales unavailable")
|
||||
}
|
||||
return s.Scales.ListAllAdmin(ctx)
|
||||
}
|
||||
|
||||
// PatchScaleStatus updates published|draft and audits in one transaction.
|
||||
func (s *Service) PatchScaleStatus(ctx context.Context, adminID, scaleID uuid.UUID, status string) error {
|
||||
if status != "published" && status != "draft" {
|
||||
return ErrInvalidScaleStatus
|
||||
}
|
||||
if s.Scales == nil {
|
||||
return errors.New("scales unavailable")
|
||||
}
|
||||
meta, _ := json.Marshal(map[string]any{"status": status})
|
||||
if err := s.Scales.UpdateStatusWithAudit(ctx, scaleID, status, adminID, meta); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return ErrScaleNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user