package com.vote.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vote.system.domain.VoteSubmissionForm;
import com.vote.system.domain.vo.VoteSubmissionFormVo;
import com.vote.system.service.VoteFormTemplatesService;
import com.vote.system.service.VoteSubmissionFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author feng
 * @date 2024/8/11
 */
@Validated
@RestController
@RequestMapping("/voteSubmissionForm")
public class VoteSubmissionFormController {

    @Autowired
    private VoteSubmissionFormService voteSubmissionFormService;

    /**
     * 分页查询
     *
     * @param voteSubmissionForm
     * @return
     */
    @GetMapping("/page")
    public AjaxResult page(VoteSubmissionForm voteSubmissionForm) {
        IPage<VoteSubmissionForm> page = voteSubmissionFormService.selectPage(voteSubmissionForm);
        return AjaxResult.success(page);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Integer id) {
        return AjaxResult.success(voteSubmissionFormService.getById(id));
    }

    /**
     * 保存提交作品表单
     *
     * @param voteSubmissionForm
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody  @Valid VoteSubmissionForm voteSubmissionForm) {
        return AjaxResult.success(voteSubmissionFormService.add(voteSubmissionForm));
    }

    /**
     * 修改提交作品表单
     *
     * @param voteSubmissionForm
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid  VoteSubmissionForm voteSubmissionForm) {
        return AjaxResult.success(voteSubmissionFormService.editById(voteSubmissionForm));
    }


    /**
     * 删除提交作品表单
     *
     * @param id
     * @return
     */
    @RequiresPermissions("vote:rule:remove")
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return AjaxResult.success(voteSubmissionFormService.removeById(id));
    }


    @GetMapping("/getSubmission")
    public AjaxResult getSubmission(String date){
        return AjaxResult.success(voteSubmissionFormService.getSubmission(date));
    }
}
