app-cloudep-tweeting-service/internal/logic/socialnetworkservice/remove_follow_relation_logi...

58 lines
1.6 KiB
Go

package socialnetworkservicelogic
import (
"app-cloudep-tweeting-service/internal/domain"
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 RemoveFollowRelationLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewRemoveFollowRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveFollowRelationLogic {
return &RemoveFollowRelationLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// RemoveFollowRelation 取消關注
func (l *RemoveFollowRelationLogic) RemoveFollowRelation(in *tweeting.DoFollowerRelationReq) (*tweeting.OKResp, error) {
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&doFollowReq{
FollowerUID: in.GetFollowerUid(),
FolloweeUID: in.GetFolloweeUid(),
}); err != nil {
// 錯誤代碼 05-011-00
return nil, ers.InvalidFormat(err.Error())
}
// 這裡要幫刪除關係, follower 追蹤 -> followee
err := l.svcCtx.SocialNetworkRepository.RemoveFollowerRelation(l.ctx, in.GetFollowerUid(), in.GetFolloweeUid())
if err != nil {
// 錯誤代碼 05-021-35
e := domain.CommentErrorL(
domain.RemoveRelationErrorCode,
logx.WithContext(l.ctx),
[]logx.LogField{
{Key: "req", Value: in},
{Key: "func", Value: "SocialNetworkRepository.RemoveFollowerRelation"},
{Key: "err", Value: err},
},
"failed to remove relation form -> to", in.GetFollowerUid(), in.GetFolloweeUid()).Wrap(err)
return nil, e
}
return &tweeting.OKResp{}, nil
}