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

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

import javax.validation.Valid;


/**
 * 问题答案表(QuestionAnswer)表控制层
 *
 * @author java
 * @since 2020-12-07 11:36:23
 */

@RestController
@RequestMapping("/new/api/back/questionAnswer")
public class BackQuestionAnswerController {

    /**
     * 服务对象
     */
    private final QuestionAnswerService questionAnswerService;

    public BackQuestionAnswerController(QuestionAnswerService questionAnswerService) {
        this.questionAnswerService = questionAnswerService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 QuestionAnswer", response = Result.class)
    public Result addBackQuestionAnswer(@Valid @RequestBody QuestionAnswer questionAnswer) {
        return Result.success(questionAnswerService.insert(questionAnswer));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 QuestionAnswer", response = Result.class)
    public Result updateBackQuestionAnswer(@RequestBody QuestionAnswer questionAnswer) {
        return Result.success(questionAnswerService.update(questionAnswer));
    }

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

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


}