package com.hc.gpweb.controller.back;


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

import javax.validation.Valid;


/**
 * 新闻分类(NewsType)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:06
 */

@RestController
@RequestMapping("/api/back/newsType")
public class BackNewsTypeController {

    /**
     * 服务对象
     */
    private final WebNewsTypeService newsTypeService;

    public BackNewsTypeController(WebNewsTypeService newsTypeService) {
        this.newsTypeService = newsTypeService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 分类", response = Result.class)
    public Result addBackCourse(@Valid @RequestBody WebNewsType course) {
        return Result.success(newsTypeService.insert(course));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 分类", response = Result.class)
    public Result updateBackCourse(@RequestBody WebNewsType course) {
        return Result.success(newsTypeService.update(course));
    }

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

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


}