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 GetCommentLikesByIdLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetCommentLikesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentLikesByIdLogic { return &GetCommentLikesByIdLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *GetCommentLikesByIdLogic) GetCommentLikesById(in *pb.GetCommentLikesByIdReq) (*pb.GetCommentLikesByIdResp, 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.CommentLikes { if like.GetCommentId() == in.GetId() { cp := *like return &pb.GetCommentLikesByIdResp{CommentLikes: &cp}, nil } } return nil, errors.New("comment like not found") }