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

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

import java.util.List;

/**
 * 帖子媒体 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface PostMediaMapper extends BaseMapperX<PostMediaDO> {

    /**
     * 查询帖子的媒体列表
     */
    default List<PostMediaDO> selectListByPostId(Long postId) {
        return selectList(new LambdaQueryWrapperX<PostMediaDO>()
                .eq(PostMediaDO::getPostId, postId)
                .orderByAsc(PostMediaDO::getSort)
                .orderByAsc(PostMediaDO::getCreateTime));
    }

    /**
     * 批量查询帖子的媒体列表
     */
    default List<PostMediaDO> selectListByPostIds(List<Long> postIds) {
        return selectList(new LambdaQueryWrapperX<PostMediaDO>()
                .in(PostMediaDO::getPostId, postIds)
                .orderByAsc(PostMediaDO::getPostId)
                .orderByAsc(PostMediaDO::getSort)
                .orderByAsc(PostMediaDO::getCreateTime));
    }

    /**
     * 删除帖子的所有媒体
     */
    default void deleteByPostId(Long postId) {
        delete(new LambdaQueryWrapperX<PostMediaDO>()
                .eq(PostMediaDO::getPostId, postId));
    }

}

