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

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

import javax.validation.Valid;


/**
 * 章节附件表(CourseChapterAnnex)表控制层
 *
 * @author java
 * @since 2020-11-09 10:04:50
 */

@RestController
@RequestMapping("/new/api/courseChapterAnnex")
public class CourseChapterAnnexController {

    /**
     * 服务对象
     */
    private final CourseChapterAnnexService courseChapterAnnexService;

    public CourseChapterAnnexController(CourseChapterAnnexService courseChapterAnnexService) {
        this.courseChapterAnnexService = courseChapterAnnexService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseChapterAnnex", response = Result.class)
    public Result addCourseChapterAnnex(@Valid @RequestBody CourseChapterAnnex courseChapterAnnex) {
        return Result.success(courseChapterAnnexService.insert(courseChapterAnnex));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapterAnnex", response = Result.class)
    public Result updateCourseChapterAnnex(@RequestBody CourseChapterAnnex courseChapterAnnex) {
        return Result.success(courseChapterAnnexService.update(courseChapterAnnex));
    }

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

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


}