63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package timelineservicelogic
|
|
|
|
import (
|
|
"app-cloudep-tweeting-service/internal/domain"
|
|
"context"
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
|
|
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
|
|
"app-cloudep-tweeting-service/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type HasNoMoreDataLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewHasNoMoreDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HasNoMoreDataLogic {
|
|
return &HasNoMoreDataLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
type hasNoMoreDataReq struct {
|
|
UID string `json:"uid" validate:"required"`
|
|
}
|
|
|
|
// HasNoMoreData 檢查時間線是否已完整,決定是否需要查詢資料庫。
|
|
func (l *HasNoMoreDataLogic) HasNoMoreData(in *tweeting.DoNoMoreDataReq) (*tweeting.HasNoMoreDataResp, error) {
|
|
// 驗證資料
|
|
if err := l.svcCtx.Validate.ValidateAll(&hasNoMoreDataReq{
|
|
UID: in.GetUid(),
|
|
}); err != nil {
|
|
// 錯誤代碼 05-011-00
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
}
|
|
|
|
res, err := l.svcCtx.TimelineRepo.HasNoMoreData(l.ctx, in.GetUid())
|
|
if err != nil {
|
|
// 錯誤代碼 05-021-23
|
|
e := domain.CommentErrorL(
|
|
domain.HasNoMoreDataErrorCode,
|
|
logx.WithContext(l.ctx),
|
|
[]logx.LogField{
|
|
{Key: "req", Value: in},
|
|
{Key: "func", Value: "TimelineRepo.HasNoMoreData"},
|
|
{Key: "err", Value: err},
|
|
},
|
|
"failed to get no more data flag:", in.GetUid()).Wrap(err)
|
|
|
|
return nil, e
|
|
}
|
|
|
|
return &tweeting.HasNoMoreDataResp{
|
|
Status: res,
|
|
}, nil
|
|
}
|