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

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

import javax.validation.Valid;


/**
 * 随机试卷问题表(PaperQuestion)表控制层
 *
 * @author java
 * @since 2020-12-07 11:35:16
 */

@RestController
@RequestMapping("/new/api/back/paperQuestion")
public class BackPaperQuestionController {

    /**
     * 服务对象
     */
    private final PaperQuestionService paperQuestionService;

    public BackPaperQuestionController(PaperQuestionService paperQuestionService) {
        this.paperQuestionService = paperQuestionService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 PaperQuestion", response = Result.class)
    public Result addBackPaperQuestion(@Valid @RequestBody PaperQuestion paperQuestion) {
        return Result.success(paperQuestionService.insert(paperQuestion));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 PaperQuestion", response = Result.class)
    public Result updateBackPaperQuestion(@RequestBody PaperQuestion paperQuestion) {
        return Result.success(paperQuestionService.update(paperQuestion));
    }

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

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

    @GetMapping("/paper/{paperId}")
    @ApiOperation(value = "依据试卷id获取 PaperQuestion", response = Result.class)
    public Result selectPaperQuestionByPaperId(@ApiParam(value = "试卷") @PathVariable("paperId") Integer paperId) {
        return Result.success(this.paperQuestionService.queryByPaperId(paperId));
    }

}