thread-master/apps/backend/internal/logic/radar/suggest_watch_terms_logic.go

42 lines
1.1 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 radar
import (
"context"
"apps/backend/internal/svc"
"apps/backend/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SuggestWatchTermsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSuggestWatchTermsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SuggestWatchTermsLogic {
return &SuggestWatchTermsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// SuggestWatchTerms 只回建議,不寫入任何 watch使用者要逐條決定採不採用RW-03
func (l *SuggestWatchTermsLogic) SuggestWatchTerms(req *types.SuggestWatchTermsReq) (resp *types.WatchSuggestData, err error) {
uid, err := ownerUID(l.ctx)
if err != nil {
return nil, err
}
list, err := l.svcCtx.Radar.SuggestWatchTerms(l.ctx, uid, req.Limit)
if err != nil {
return nil, err
}
out := make([]types.WatchTermSuggestion, 0, len(list))
for _, s := range list {
out = append(out, types.WatchTermSuggestion{Term: s.Term, Reason: s.Reason, Usage: s.Usage})
}
return &types.WatchSuggestData{List: out}, nil
}