package com.hc.gpweb.controller.api;

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

import javax.validation.Valid;


/**
 * 课程标签表(CourseTag)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:09
 */

@RestController
@RequestMapping("/api/courseTag")
public class CourseTagController {

    /**
     * 服务对象
     */
    private final WebCourseTagService courseTagService;

    public CourseTagController(WebCourseTagService courseTagService) {
        this.courseTagService = courseTagService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 CourseTag", response = Result.class)
    public Result addCourseTag(@Valid @RequestBody WebCourseTag courseTag) {
        return Result.success(courseTagService.insert(courseTag));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 CourseTag", response = Result.class)
    public Result updateCourseTag(@RequestBody WebCourseTag courseTag) {
        return Result.success(courseTagService.update(courseTag));
    }

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

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


}