feat(ECR-020): QualityFeedback 问答质量反馈并 Closed
新增 ask_quality_feedback、运营/C端评分 API 与 admin-h5 问答反馈区;禁改消息/UGC/真支付。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
Reference in New Issue
Block a user