package com.vote.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vote.system.domain.VoteFormTemplates;
import com.vote.system.domain.dto.VoteFormTemplatesDto;
import com.vote.system.service.VoteFormTemplatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
@Validated
@RestController
@RequestMapping("/formTemplates")
public class VoteFormTemplatesController {

    @Autowired
    private VoteFormTemplatesService voteFormTemplatesService;

    /**
     * 分页查询
     *
     * @param voteFormTemplates 实体
     * @return
     */
    @GetMapping("/page")
    public AjaxResult page(VoteFormTemplates voteFormTemplates) {
        IPage<VoteFormTemplates> page = voteFormTemplatesService.selectPage(voteFormTemplates);
        return AjaxResult.success(page);
    }


    /**
     * 添加 报名表单内容项
     *
     * @param voteFormTemplates 接收前端传参
     * @return 状态
     */
    @PostMapping
    public AjaxResult createVoteFormTemplates(@RequestBody @Valid VoteFormTemplates voteFormTemplates) {
        return AjaxResult.success(voteFormTemplatesService.createVoteFormTemplates(voteFormTemplates));
    }

    /**
     * 修改 表单项
     * @param voteFormTemplates
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult editVoteFormTemplates(@RequestBody @Valid VoteFormTemplates voteFormTemplates) {
        return AjaxResult.success(voteFormTemplatesService.editVoteFormTemplates(voteFormTemplates));
    }


    /**
     * 删除内容项
     * @param voteFormTemplatesDto
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody VoteFormTemplatesDto voteFormTemplatesDto) {
        return AjaxResult.success(voteFormTemplatesService.deleteById(voteFormTemplatesDto));
    }


}
