package com.ruoyi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.annotations.UserLoginToken;
import com.ruoyi.common.page.PageResult;
import com.ruoyi.controller.req.LikeReq;
import com.ruoyi.controller.req.NewsPageReq;
import com.ruoyi.frequency.like.service.LikeService;
import com.ruoyi.frequency.news.entity.News;
import com.ruoyi.frequency.news.service.NewsService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.BodyIdReq;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 新闻
 */
@CrossOrigin
@RestController
@RequestMapping("/api/news")
@Api(tags = "新闻")
public class ApiNewsController extends RyController {

    @Autowired
    private NewsService newsService;

    @PostMapping("/newsPage")
    @ApiOperation(value = "新闻列表", notes = "新闻列表")
//    @UserLoginToken
    public ResponseData<PageResult<Page<News>>> newsPage(@RequestBody @Valid NewsPageReq req) {
        return newsService.newsPage(req,getUserVo());
    }

    @PostMapping("/newsDetail")
    @ApiOperation(value = "新闻详情", notes = "新闻详情")
//    @UserLoginToken
    public ResponseData<News> newsDetail(@RequestBody @Valid BodyIdReq req) {
        return newsService.newsDetail(req.getId(),req.getIsAddBrowseNum(),getUserVo());
    }

    @Autowired
    private LikeService likeService;

    @PostMapping("/newsLike")
    @UserLoginToken
    @ApiOperation(value = "新闻点赞", notes = "新闻点赞")
    public ResponseData newsLike(@RequestBody LikeReq req) {
        return likeService.like(req,getUserVo());
    }
}
