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.VoteWorkTypes;
import com.vote.system.service.VoteWorkTypesService;
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/12
 */
@Validated
@RestController
@RequestMapping("/workTypes")
public class VoteWorkTypesController {

    @Autowired
    private VoteWorkTypesService voteWorkTypesService;


    /**
     * 分页查询
     *
     * @param voteWorkTypes
     * @return
     */
    @GetMapping("/page")
    public AjaxResult getWorkTypes(VoteWorkTypes voteWorkTypes) {
        IPage<VoteWorkTypes> page = voteWorkTypesService.selectPage(voteWorkTypes);
        return AjaxResult.success(page);
    }


    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid VoteWorkTypes voteWorkTypes) {
        return AjaxResult.success(voteWorkTypesService.updateById(voteWorkTypes));
    }


    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        return AjaxResult.success(voteWorkTypesService.deleteById(id));
    }


    @PostMapping
    public AjaxResult save(@RequestBody VoteWorkTypes voteWorkTypes) {
        return AjaxResult.success(voteWorkTypesService.add(voteWorkTypes));
    }

}
