70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
|
package socialnetworkservicelogic
|
||
|
|
||
|
import (
|
||
|
"app-cloudep-tweeting-service/internal/domain"
|
||
|
"app-cloudep-tweeting-service/internal/domain/repository"
|
||
|
ers "code.30cm.net/digimon/library-go/errs"
|
||
|
"context"
|
||
|
|
||
|
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
|
||
|
"app-cloudep-tweeting-service/internal/svc"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type GetFolloweeLogic struct {
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
logx.Logger
|
||
|
}
|
||
|
|
||
|
func NewGetFolloweeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFolloweeLogic {
|
||
|
return &GetFolloweeLogic{
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// GetFollowee 取得我跟隨的名單
|
||
|
func (l *GetFolloweeLogic) GetFollowee(in *tweeting.FollowReq) (*tweeting.FollowResp, error) {
|
||
|
// 驗證資料
|
||
|
if err := l.svcCtx.Validate.ValidateAll(&getFollowReq{
|
||
|
UID: in.Uid,
|
||
|
PageSize: in.PageSize,
|
||
|
PageIndex: in.PageIndex,
|
||
|
}); err != nil {
|
||
|
// 錯誤代碼 05-011-00
|
||
|
return nil, ers.InvalidFormat(err.Error())
|
||
|
}
|
||
|
|
||
|
followee, err := l.svcCtx.SocialNetworkRepository.GetFollowee(l.ctx, repository.FollowReq{
|
||
|
UID: in.GetUid(),
|
||
|
PageIndex: in.GetPageIndex(),
|
||
|
PageSize: in.GetPageSize(),
|
||
|
})
|
||
|
if err != nil {
|
||
|
// 錯誤代碼 05-021-33
|
||
|
e := domain.CommentErrorL(
|
||
|
domain.GetFolloweeErrorCode,
|
||
|
logx.WithContext(l.ctx),
|
||
|
[]logx.LogField{
|
||
|
{Key: "req", Value: in},
|
||
|
{Key: "func", Value: "SocialNetworkRepository.GetFollowee"},
|
||
|
{Key: "err", Value: err},
|
||
|
},
|
||
|
"failed to get relation: ", in.GetUid()).Wrap(err)
|
||
|
|
||
|
return nil, e
|
||
|
}
|
||
|
|
||
|
return &tweeting.FollowResp{
|
||
|
Uid: followee.UIDs,
|
||
|
Page: &tweeting.Pager{
|
||
|
Total: followee.Total,
|
||
|
Index: in.GetPageIndex(),
|
||
|
Size: in.GetPageSize(),
|
||
|
},
|
||
|
}, nil
|
||
|
}
|