Ask/catalog 权限与审计加固、量表读权限统一,以及未提交的 ops hardening 变更。 Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
)
|
|
|
|
var (
|
|
ErrBadFeedbackRating = errString("rating must be 1-5")
|
|
ErrBadFeedbackTag = errString("invalid tag")
|
|
ErrFeedbackNoteLong = errString("note too long")
|
|
ErrMessageNotInThread = errString("message not in thread")
|
|
)
|
|
|
|
// ListQualityFeedback lists recent QualityFeedback.
|
|
func (s *Service) ListQualityFeedback(ctx context.Context, limit, offset int) ([]repository.QualityFeedbackRow, error) {
|
|
items, err := s.Repo.ListQualityFeedback(ctx, limit, offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if items == nil {
|
|
items = []repository.QualityFeedbackRow{}
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
// CreateQualityFeedback is ops-submitted feedback.
|
|
func (s *Service) CreateQualityFeedback(
|
|
ctx context.Context, adminID, threadID uuid.UUID, messageID *uuid.UUID, rating int, tag, note string,
|
|
) (*repository.QualityFeedbackRow, error) {
|
|
var tagPtr, notePtr *string
|
|
if strings.TrimSpace(tag) != "" {
|
|
t := strings.TrimSpace(tag)
|
|
tagPtr = &t
|
|
}
|
|
if strings.TrimSpace(note) != "" {
|
|
n := strings.TrimSpace(note)
|
|
notePtr = &n
|
|
}
|
|
row, err := s.Repo.CreateAdminQualityFeedback(ctx, adminID, threadID, messageID, rating, tagPtr, notePtr)
|
|
if err == nil {
|
|
return row, nil
|
|
}
|
|
msg := err.Error()
|
|
switch {
|
|
case strings.Contains(msg, "rating"):
|
|
return nil, ErrBadFeedbackRating
|
|
case strings.Contains(msg, "tag"):
|
|
return nil, ErrBadFeedbackTag
|
|
case strings.Contains(msg, "note"):
|
|
return nil, ErrFeedbackNoteLong
|
|
case strings.Contains(msg, "thread not found"):
|
|
return nil, ErrAskThreadNotFound
|
|
case strings.Contains(msg, "message not in thread"):
|
|
return nil, ErrMessageNotInThread
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|