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

import com.xindazhou.business.dal.community.dataobject.collect.CollectDO;
import com.xindazhou.framework.common.pojo.PageResult;
import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.xindazhou.business.controller.app.community.collect.vo.CollectPageReqVO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 收藏 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface CollectMapper extends BaseMapperX<CollectDO> {

    default PageResult<CollectDO> selectPage(CollectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CollectDO>()
                .eqIfPresent(CollectDO::getUserId, reqVO.getUserId())
                .orderByDesc(CollectDO::getCreateTime));
    }

    /**
     * 查询用户是否已收藏
     */
    default CollectDO selectByUserIdAndPostId(Long userId, Long postId) {
        return selectOne(new LambdaQueryWrapperX<CollectDO>()
                .eq(CollectDO::getUserId, userId)
                .eq(CollectDO::getPostId, postId));
    }

}

