package com.hc.gpweb.controller.api;

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

import javax.validation.Valid;


/**
 * 图书章节标签表。新建完成的图书章节，可以根据讲师不同，给不同的章节打标签，比如基础阶段，进阶阶段。。。(CourseChapterTag)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:07
 */

@RestController
@RequestMapping("/api/courseChapterTag")
public class CourseChapterTagController {

    /**
     * 服务对象
     */
    private final WebCourseChapterTagService courseChapterTagService;

    public CourseChapterTagController(WebCourseChapterTagService courseChapterTagService) {
        this.courseChapterTagService = courseChapterTagService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseChapterTag", response = Result.class)
    public Result addCourseChapterTag(@Valid @RequestBody WebCourseChapterTag courseChapterTag) {
        return Result.success(courseChapterTagService.insert(courseChapterTag));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseChapterTag", response = Result.class)
    public Result updateCourseChapterTag(@RequestBody WebCourseChapterTag courseChapterTag) {
        return Result.success(courseChapterTagService.update(courseChapterTag));
    }

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

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


}