Files

42 lines
991 B
Go

package logic
import (
"context"
"errors"
"juwan-backend/app/community/rpc/internal/models/postlikes"
"juwan-backend/app/community/rpc/internal/svc"
"juwan-backend/app/community/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetPostLikesByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetPostLikesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostLikesByIdLogic {
return &GetPostLikesByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetPostLikesByIdLogic) GetPostLikesById(in *pb.GetPostLikesByIdReq) (*pb.GetPostLikesByIdResp, error) {
if in.GetId() <= 0 {
return nil, errors.New("id is required")
}
like, err := l.svcCtx.CommunityModelRO.PostLikes.Query().
Where(postlikes.PostIDEQ(in.GetId())).
First(l.ctx)
if err != nil {
return nil, errors.New("post like not found")
}
return &pb.GetPostLikesByIdResp{PostLikes: entPostLikeToPb(like)}, nil
}