package com.hc.gpweb.controller.back;

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

import javax.validation.Valid;


/**
 * 课程章节表(CourseChapter)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:06
 */

@RestController
@RequestMapping("/api/back/courseChapter")
public class BackCourseChapterController {

    /**
     * 服务对象
     */
    private final WebCourseChapterService courseChapterService;

    public BackCourseChapterController(WebCourseChapterService courseChapterService) {
        this.courseChapterService = courseChapterService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseChapter", response = Result.class)
    public Result addBackCourseChapter(@Valid @RequestBody WebCourseChapter courseChapter) {
        return Result.success(courseChapterService.insert(courseChapter));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapter", response = Result.class)
    public Result updateBackCourseChapter(@RequestBody WebCourseChapter courseChapter) {
        return Result.success(courseChapterService.update(courseChapter));
    }

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

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


}