package com.hc.web.controller.browser.back;

import com.hc.business.model.Paper;
import com.hc.business.service.PaperService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 试卷表(Paper)表控制层
 *
 * @author java
 * @since 2020-12-07 11:34:40
 */

@RestController
@RequestMapping("/new/api/back/paper")
public class BackPaperController {

    /**
     * 服务对象
     */
    private final PaperService paperService;

    public BackPaperController(PaperService paperService) {
        this.paperService = paperService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 Paper", response = Result.class)
    public Result selectBackPaper(@PathVariable("id") Integer id) {
        return Result.success(this.paperService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 Paper", response = Result.class)
    public Result addBackPaper(@Valid @RequestBody Paper paper) {
        return Result.success(paperService.insert(paper));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 Paper", response = Result.class)
    public Result updateBackPaper(@RequestBody Paper paper) {
        return Result.success(paperService.update(paper));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 Paper", response = Result.class)
    public Result deleteBackPaper(@PathVariable("id") Integer id) {
        return Result.success(paperService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 Paper列表(分页)", response = Result.class)
    public Result listBackPaper(@RequestParam(defaultValue = "0") Integer page,
                                @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(paperService.queryAllByLimit(page, size));
    }


}