2024-08-28 09:09:01 +00:00
|
|
|
|
package postservicelogic
|
|
|
|
|
|
|
|
|
|
import (
|
2024-08-29 13:49:47 +00:00
|
|
|
|
"app-cloudep-tweeting-service/internal/domain"
|
|
|
|
|
model "app-cloudep-tweeting-service/internal/model/mongo"
|
2024-08-28 09:09:01 +00:00
|
|
|
|
"context"
|
|
|
|
|
|
2024-08-29 14:50:09 +00:00
|
|
|
|
ers "code.30cm.net/digimon/library-go/errs"
|
|
|
|
|
|
2024-08-28 14:29:42 +00:00
|
|
|
|
"app-cloudep-tweeting-service/gen_result/pb/tweeting"
|
|
|
|
|
"app-cloudep-tweeting-service/internal/svc"
|
2024-08-28 09:09:01 +00:00
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetLikeStatusLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
logx.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewGetLikeStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLikeStatusLogic {
|
|
|
|
|
return &GetLikeStatusLogic{
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 13:26:01 +00:00
|
|
|
|
// 這個人按讚的文章列表(輸入UID 以及文章id,返回這個人有沒有對這些文章按讚)
|
2024-08-29 13:49:47 +00:00
|
|
|
|
type getLikeStatusReq struct {
|
|
|
|
|
Targets []string `json:"targets" validate:"required"`
|
|
|
|
|
LikeType domain.LikeType `json:"like_type" validate:"required,oneof=1 2"`
|
|
|
|
|
UID string `json:"uid" validate:"required"`
|
|
|
|
|
}
|
2024-08-29 13:26:01 +00:00
|
|
|
|
|
2024-08-28 09:09:01 +00:00
|
|
|
|
// GetLikeStatus 取得讚/不讚狀態
|
2024-08-29 13:49:47 +00:00
|
|
|
|
func (l *GetLikeStatusLogic) GetLikeStatus(in *tweeting.GetLikeStatusReq) (*tweeting.GetLikeStatusResp, error) {
|
|
|
|
|
// 驗證資料
|
|
|
|
|
if err := l.svcCtx.Validate.ValidateAll(&getLikeStatusReq{
|
|
|
|
|
Targets: in.GetTargetId(),
|
|
|
|
|
LikeType: domain.LikeType(in.GetLikeType()),
|
|
|
|
|
UID: in.GetUid(),
|
|
|
|
|
}); err != nil {
|
|
|
|
|
return nil, ers.InvalidFormat(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list, err := l.svcCtx.PostLikeModel.FindUIDPostLikeStatus(l.ctx, &model.QueryUIDPostLikeStatusReq{
|
|
|
|
|
Targets: in.GetTargetId(),
|
|
|
|
|
LikeType: domain.LikeType(in.GetLikeType()),
|
|
|
|
|
UID: in.GetUid(),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
e := domain.PostMongoErrorL(
|
|
|
|
|
logx.WithContext(l.ctx),
|
|
|
|
|
[]logx.LogField{
|
|
|
|
|
{Key: "req", Value: in},
|
|
|
|
|
{Key: "func", Value: "PostModel.FindUIDPostLikeStatus"},
|
|
|
|
|
{Key: "err", Value: err},
|
|
|
|
|
},
|
|
|
|
|
"failed to find uid post like status list").Wrap(err)
|
|
|
|
|
return nil, e
|
|
|
|
|
}
|
|
|
|
|
var result = make([]*tweeting.GetLikeStatusItem, 0, len(list))
|
|
|
|
|
|
|
|
|
|
for _, item := range list {
|
|
|
|
|
result = append(result, &tweeting.GetLikeStatusItem{
|
|
|
|
|
TargetId: item.TargetID,
|
|
|
|
|
Status: item.LikeStatus,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-08-28 09:09:01 +00:00
|
|
|
|
|
2024-08-29 13:49:47 +00:00
|
|
|
|
return &tweeting.GetLikeStatusResp{
|
|
|
|
|
Data: result,
|
|
|
|
|
}, nil
|
2024-08-28 09:09:01 +00:00
|
|
|
|
}
|