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

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

import javax.validation.Valid;


/**
 * (CourseTypeRelation)表控制层
 *
 * @author java
 * @since 2021-02-02 09:25:14
 */

@RestController
@RequestMapping("/new/api/back/courseTypeRelation")
public class BackCourseTypeRelationController {

    /**
     * 服务对象
     */
    private final CourseTypeRelationService courseTypeRelationService;

    public BackCourseTypeRelationController(CourseTypeRelationService courseTypeRelationService) {
        this.courseTypeRelationService = courseTypeRelationService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseTypeRelation", response = Result.class)
    public Result addCourseTypeRelation(@Valid @RequestBody CourseTypeRelation courseTypeRelation) {
        return Result.success(courseTypeRelationService.insert(courseTypeRelation));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseTypeRelation", response = Result.class)
    public Result updateCourseTypeRelation(@RequestBody CourseTypeRelation courseTypeRelation) {
        return Result.success(courseTypeRelationService.update(courseTypeRelation));
    }

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

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


}