2024-09-03 09:11:12 +00:00
|
|
|
package socialnetworkservicelogic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"app-cloudep-tweeting-service/internal/domain"
|
|
|
|
"context"
|
|
|
|
|
2024-09-03 09:47:34 +00:00
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
|
|
|
2024-09-03 09:11:12 +00:00
|
|
|
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
|
|
|
|
"app-cloudep-tweeting-service/internal/svc"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetFolloweeCountLogic struct {
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
logx.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetFolloweeCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFolloweeCountLogic {
|
|
|
|
return &GetFolloweeCountLogic{
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFolloweeCount 取得我跟隨的數量
|
|
|
|
func (l *GetFolloweeCountLogic) GetFolloweeCount(in *tweeting.FollowCountReq) (*tweeting.FollowCountResp, error) {
|
|
|
|
// 驗證資料
|
|
|
|
if err := l.svcCtx.Validate.ValidateAll(&getFollowCountReq{
|
|
|
|
UID: in.Uid,
|
|
|
|
}); err != nil {
|
|
|
|
// 錯誤代碼 05-011-00
|
|
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
followeeCount, err := l.svcCtx.SocialNetworkRepository.GetFolloweeCount(l.ctx, in.GetUid())
|
|
|
|
if err != nil {
|
|
|
|
// 錯誤代碼 05-021-34
|
|
|
|
e := domain.CommentErrorL(
|
|
|
|
domain.GetFolloweeCountErrorCode,
|
|
|
|
logx.WithContext(l.ctx),
|
|
|
|
[]logx.LogField{
|
|
|
|
{Key: "req", Value: in},
|
|
|
|
{Key: "func", Value: "SocialNetworkRepository.GetFolloweeCount"},
|
|
|
|
{Key: "err", Value: err},
|
|
|
|
},
|
|
|
|
"failed to count follower").Wrap(err)
|
|
|
|
|
|
|
|
return nil, e
|
|
|
|
}
|
|
|
|
|
|
|
|
return &tweeting.FollowCountResp{
|
|
|
|
Uid: in.GetUid(),
|
|
|
|
Total: followeeCount,
|
|
|
|
}, nil
|
|
|
|
}
|