package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleLikeMapper;
import com.gxwebsoft.cms.service.ArticleLikeService;
import com.gxwebsoft.cms.entity.ArticleLike;
import com.gxwebsoft.cms.param.ArticleLikeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 点赞文章Service实现
 *
 * @author 科技小王子
 * @since 2023-07-07 13:00:03
 */
@Service
public class ArticleLikeServiceImpl extends ServiceImpl<ArticleLikeMapper, ArticleLike> implements ArticleLikeService {

    @Override
    public PageResult<ArticleLike> pageRel(ArticleLikeParam param) {
        PageParam<ArticleLike, ArticleLikeParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<ArticleLike> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<ArticleLike> listRel(ArticleLikeParam param) {
        List<ArticleLike> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<ArticleLike, ArticleLikeParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public ArticleLike getByIdRel(Integer id) {
        ArticleLikeParam param = new ArticleLikeParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
