Ask/catalog 权限与审计加固、量表读权限统一,以及未提交的 ops hardening 变更。 Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package ask
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/repository"
|
|
)
|
|
|
|
// SubmitFeedbackInput for C-end QualityFeedback.
|
|
type SubmitFeedbackInput struct {
|
|
MessageID *uuid.UUID
|
|
Rating int
|
|
Tag string
|
|
Note string
|
|
}
|
|
|
|
// SubmitFeedback records user QualityFeedback on owned thread.
|
|
func (s *Service) SubmitFeedback(ctx context.Context, userID, threadID uuid.UUID, in SubmitFeedbackInput) (*repository.QualityFeedbackRow, error) {
|
|
var tagPtr, notePtr *string
|
|
if t := strings.TrimSpace(in.Tag); t != "" {
|
|
tagPtr = &t
|
|
}
|
|
if n := strings.TrimSpace(in.Note); n != "" {
|
|
notePtr = &n
|
|
}
|
|
row, err := s.Ask.CreateUserQualityFeedback(ctx, userID, threadID, in.MessageID, in.Rating, tagPtr, notePtr)
|
|
if err == nil {
|
|
return row, nil
|
|
}
|
|
msg := err.Error()
|
|
if strings.Contains(msg, "rating") || strings.Contains(msg, "tag") || strings.Contains(msg, "note") {
|
|
return nil, errors.New(msg)
|
|
}
|
|
if strings.Contains(msg, "thread not found") {
|
|
return nil, errors.New("ask thread not found")
|
|
}
|
|
if strings.Contains(msg, "message not in thread") {
|
|
return nil, errors.New("message not in thread")
|
|
}
|
|
return nil, err
|
|
}
|