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

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

import javax.validation.Valid;


/**
 * 问题类型表(QuestionType)表控制层
 *
 * @author java
 * @since 2020-12-07 11:37:04
 */

@RestController
@RequestMapping("/new/api/back/questionType")
public class BackQuestionTypeController {

    /**
     * 服务对象
     */
    private final QuestionTypeService questionTypeService;

    public BackQuestionTypeController(QuestionTypeService questionTypeService) {
        this.questionTypeService = questionTypeService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 QuestionType", response = Result.class)
    public Result addBackQuestionType(@Valid @RequestBody QuestionType questionType) {
        return Result.success(questionTypeService.insert(questionType));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 QuestionType", response = Result.class)
    public Result updateBackQuestionType(@RequestBody QuestionType questionType) {
        return Result.success(questionTypeService.update(questionType));
    }

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

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


}