package com.hc.gpweb.controller.api;

import com.hc.gpbusiness.model.WebCourseChapterTest;
import com.hc.gpbusiness.service.WebCourseChapterTestService;
import com.hc.gpcore.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 章节测试表/随堂练习表(CourseChapterTest)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:08
 */

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

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

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

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

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

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapterTest", response = Result.class)
    public Result updateCourseChapterTest(@RequestBody WebCourseChapterTest 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));
    }


}