package com.hc.gpweb.controller.back;


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

import javax.validation.Valid;


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

@RestController
@RequestMapping("/api/back/course")
public class BackCourseController {

    /**
     * 服务对象
     */
    private final WebCourseService courseService;

    public BackCourseController(WebCourseService courseService) {
        this.courseService = courseService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 Course", response = Result.class)
    public Result selectBackCourse(@PathVariable("id") Integer id) {
        return Result.success(this.courseService.queryModelById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 Course", response = Result.class)
    public Result addBackCourse(@Valid @RequestBody WebCourse course) {
        return Result.success(courseService.insert(course));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 Course", response = Result.class)
    public Result updateBackCourse(@RequestBody WebCourse course) {
        return Result.success(courseService.update(course));
    }

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

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


}