package com.xindazhou.business.dal.community.mysql.like;

import com.xindazhou.business.dal.community.dataobject.like.LikeDO;
import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 点赞 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface LikeMapper extends BaseMapperX<LikeDO> {

    /**
     * 查询用户是否已点赞
     */
    default LikeDO selectByUserIdAndTarget(Long userId, Integer targetType, Long targetId) {
        return selectOne(new LambdaQueryWrapperX<LikeDO>()
                .eq(LikeDO::getUserId, userId)
                .eq(LikeDO::getTargetType, targetType)
                .eq(LikeDO::getTargetId, targetId));
    }

    /**
     * 统计目标对象的点赞数
     */
    default Long selectCountByTarget(Integer targetType, Long targetId) {
        return selectCount(new LambdaQueryWrapperX<LikeDO>()
                .eq(LikeDO::getTargetType, targetType)
                .eq(LikeDO::getTargetId, targetId));
    }

}

