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

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

import javax.validation.Valid;


/**
 * 章节测试表/随堂练习表(CourseChapterTest)表控制层
 *
 * @author java
 * @since 2020-11-09 10:04:54
 */

@RestController
@RequestMapping("/new/api/courseChapterTest")
public class CourseChapterTestController {

    /**
     * 服务对象
     */
    private final CourseChapterTestService courseChapterTestService;

    public CourseChapterTestController(CourseChapterTestService courseChapterTestService) {
        this.courseChapterTestService = courseChapterTestService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseChapterTest", response = Result.class)
    public Result addCourseChapterTest(@Valid @RequestBody CourseChapterTest courseChapterTest) {
        return Result.success(courseChapterTestService.insert(courseChapterTest));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapterTest", response = Result.class)
    public Result updateCourseChapterTest(@RequestBody CourseChapterTest courseChapterTest) {
        return Result.success(courseChapterTestService.update(courseChapterTest));
    }

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

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


}