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

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

import javax.validation.Valid;


/**
 * 班次课程表(ZccmClassCourse)表控制层
 *
 * @author java
 * @since 2020-11-24 11:30:12
 */

@RestController
@RequestMapping("/new/api/back/classCourse")
public class BackClassCourseController {

    /**
     * 服务对象
     */
    private final ZccmClassCourseService classCourseService;

    public BackClassCourseController(ZccmClassCourseService classCourseService) {
        this.classCourseService = classCourseService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ZccmClassCourse", response = Result.class)
    public Result addBackClassCourse(@Valid @RequestBody ZccmClassCourse classCourse) {
        return Result.success(classCourseService.insert(classCourse));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ZccmClassCourse", response = Result.class)
    public Result updateBackClassCourse(@RequestBody ZccmClassCourse classCourse) {
        return Result.success(classCourseService.update(classCourse));
    }

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

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

    @GetMapping("/course")
    @ApiOperation(value = "获取班级 必修/选修课程", response = Result.class)
    public Result listBackClassCourseByParam(@ApiParam(value = "班次id") @RequestParam Integer classId,
                                             @ApiParam(value = "班级类别") @RequestParam(required = false) Integer courseType,
                                             @RequestParam(defaultValue = "0") Integer page,
                                             @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(classCourseService.queryByClassId(classId, courseType, page, size));
    }


}