package logic import ( "context" "errors" "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") } store := l.svcCtx.Store store.Mu.RLock() defer store.Mu.RUnlock() for _, like := range store.PostLikes { if like.GetPostId() == in.GetId() { cp := *like return &pb.GetPostLikesByIdResp{PostLikes: &cp}, nil } } return nil, errors.New("post like not found") }