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.VoteRegistrationForms;
import com.vote.system.service.VoteRegistrationFormsService;
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/9
 */
@Validated
@RestController
@RequestMapping("/registrationForms")
public class VoteRegistrationFormsController {

    @Autowired
    private VoteRegistrationFormsService voteRegistrationFormsService;


    /**
     * 分页查询 报名表单
     *
     * @param voteRegistrationForms
     * @return
     */
    @GetMapping("/page")
    public AjaxResult page(VoteRegistrationForms voteRegistrationForms) {
        IPage<VoteRegistrationForms> page = voteRegistrationFormsService.selectPage(voteRegistrationForms);
        return AjaxResult.success(page);
    }

    /**
     * 查询单个 报名表单
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        VoteRegistrationForms forms = voteRegistrationFormsService.getById(id);
        return AjaxResult.success(forms);
    }

    /**
     * 添加 报名表单
     *
     * @param voteRegistrationForms
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody @Valid VoteRegistrationForms voteRegistrationForms) {
        return AjaxResult.success(voteRegistrationFormsService.saveRegistrationForms(voteRegistrationForms));
    }

    /**
     * 查询所有内容项
     *
     * @return
     */
    @GetMapping
    public AjaxResult get() {
        return AjaxResult.success(voteRegistrationFormsService.queryByFormTemplates());
    }

    /**
     * 删除 报名表单
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id) {
        return AjaxResult.success(voteRegistrationFormsService.deleteById(id));
    }

    /**
     * 修改
     * @param voteRegistrationForms
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid VoteRegistrationForms voteRegistrationForms) {
        return AjaxResult.success(voteRegistrationFormsService.editVoteRegistrationForms(voteRegistrationForms));

    }
}
