package com.cool.store.controller.webc;

import com.cool.store.dto.content.ContentQueryDetailDto;
import com.cool.store.dto.content.ContentQueryListDto;
import com.cool.store.entity.HyContentInfoDO;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.ContentService;
import com.cool.store.vo.HyContentInfoVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mini/program/news")
@Api(tags = "小程序端动态")
@Slf4j
public class NewsContentController {

    @Autowired
    private ContentService contentService;

    @PostMapping("/queryContentList")
    @ApiOperation("查询动态列表")
    public ResponseResult<PageInfo<HyContentInfoVO>> queryContentList(@RequestBody ContentQueryListDto dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<HyContentInfoVO> list = contentService.queryContentListToC(dto);
        PageInfo<HyContentInfoVO> page = new PageInfo<>(list);
        return ResponseResult.success(page);
    }

    @PostMapping("/detail")
    @ApiOperation("动态详情")
    public ResponseResult<HyContentInfoDO> queryContentInfo(@RequestBody ContentQueryDetailDto dto) {
        return ResponseResult.success(contentService.queryContentInfo(dto.getContentId()));
    }

}
