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.VoteLikeReq;
import com.ruoyi.controller.req.VoteReq;
import com.ruoyi.controller.req.WorksLikeReq;
import com.ruoyi.controller.resp.VoteDetailResp;
import com.ruoyi.controller.resp.VotePageResp;
import com.ruoyi.frequency.vote.service.VoteService;
import com.ruoyi.frequency.votelike.service.VoteLikeService;
import com.ruoyi.response.ResponseData;
import com.ruoyi.vo.BodyIdReq;
import com.ruoyi.vo.PageBasic;
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.*;

/**
 * 投票
 * 
 * @author liwenlong
 * @date 2023-10-12
 */
@CrossOrigin
@RestController
@RequestMapping("/api/vote")
@Api(tags = "投票")
public class ApiVoteController extends RyController
{
    @Autowired
    private VoteService voteService;


    @PostMapping("/votePage")
    @ApiOperation(value = "投票列表", notes = "投票列表")
    public ResponseData<PageResult<Page<VotePageResp>>> votePage(@RequestBody PageBasic req) {
        return voteService.votePage(req,getUserVo(),false);
    }

    @PostMapping("/votePageBySelf")
    @ApiOperation(value = "我参与投票列表", notes = "我参与投票列表")
    @UserLoginToken
    public ResponseData<PageResult<Page<VotePageResp>>> votePageBySelf(@RequestBody PageBasic req) {
        return voteService.votePage(req,getUserVo(),true);
    }

    @PostMapping("/vote")
    @UserLoginToken
    @ApiOperation(value = "投票", notes = "投票")
    public ResponseData vote(@RequestBody VoteReq req) {
        return voteService.vote(req,getUserVo());
    }

    @PostMapping("/voteDetail")
    @ApiOperation(value = "投票详情", notes = "投票详情")
    public ResponseData<VoteDetailResp> voteDetail(@RequestBody BodyIdReq req) {
        return voteService.voteDetail(req.getId(),req.getIsAddBrowseNum(),getUserVo());
    }

    @Autowired
    private VoteLikeService voteLikeService;

    @PostMapping("/voteLike")
    @UserLoginToken
    @ApiOperation(value = "投票点赞", notes = "投票点赞")
    public ResponseData voteLike(@RequestBody VoteLikeReq req) {
        return voteLikeService.voteLike(req,getUserVo());
    }

}
