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

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

import javax.validation.Valid;


/**
 * 课程章节表(ZccmCourseChapter)表控制层
 *
 * @author java
 * @since 2020-11-09 10:04:48
 */

@RestController
@RequestMapping("/new/api/courseChapter")
public class CourseChapterController {

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

    public CourseChapterController(ZccmCourseChapterService courseChapterService) {
        this.courseChapterService = courseChapterService;
    }

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

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

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

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

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


}