thread-master/apps/backend/internal/logic/compose/compose_persona_preview_log...

46 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package compose
import (
"context"
"apps/backend/internal/middleware"
"apps/backend/internal/response"
"apps/backend/internal/svc"
"apps/backend/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ComposePersonaPreviewLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewComposePersonaPreviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ComposePersonaPreviewLogic {
return &ComposePersonaPreviewLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}
func (l *ComposePersonaPreviewLogic) ComposePersonaPreview(req *types.ComposePersonaPreviewReq) (*types.ComposePersonaPreviewData, error) {
if l.svcCtx.Studio == nil {
return nil, response.Biz(503, 503001, "studio not configured")
}
uid, ok := middleware.UIDFrom(l.ctx)
if !ok {
return nil, response.Biz(401, 401001, "missing authorization")
}
// UseNewsAPI 可選FE 預設 true。若 JSON 省略 bool 為 falseFE 會明確傳 true。
useNews := req.UseNews
out, err := l.svcCtx.Studio.PersonaPreview(l.ctx, uid, req.PersonaId, req.Topic, useNews)
if err != nil {
return nil, err
}
return &types.ComposePersonaPreviewData{
Topic: out.Topic,
TopicSource: out.TopicSource,
PostText: out.PostText,
ReplyText: out.ReplyText,
Notes: out.Notes,
}, nil
}