package com.hc.gpweb.controller.back;

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

import javax.validation.Valid;


/**
 * 课程视频(CourseChapterVideo)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:08
 */

@RestController
@RequestMapping("/api/back/courseChapterVideo")
public class BackCourseChapterVideoController {

    /**
     * 服务对象
     */
    private final WebCourseChapterVideoService courseChapterVideoService;

    public BackCourseChapterVideoController(WebCourseChapterVideoService courseChapterVideoService) {
        this.courseChapterVideoService = courseChapterVideoService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseChapterVideo", response = Result.class)
    public Result addBackCourseChapterVideo(@Valid @RequestBody WebCourseChapterVideo courseChapterVideo) {
        return Result.success(courseChapterVideoService.insert(courseChapterVideo));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapterVideo", response = Result.class)
    public Result updateBackCourseChapterVideo(@RequestBody WebCourseChapterVideo courseChapterVideo) {
        return Result.success(courseChapterVideoService.update(courseChapterVideo));
    }

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

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


}