package com.hc.gpweb.controller.api;

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

import javax.validation.Valid;


/**
 * 新闻标签表(NewsTag)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:11
 */

@RestController
@RequestMapping("/api/newsTag")
public class NewsTagController {

    /**
     * 服务对象
     */
    private final WebNewsTagService newsTagService;

    public NewsTagController(WebNewsTagService newsTagService) {
        this.newsTagService = newsTagService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 NewsTag", response = Result.class)
    public Result addNewsTag(@Valid @RequestBody WebNewsTag newsTag) {
        return Result.success(newsTagService.insert(newsTag));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 NewsTag", response = Result.class)
    public Result updateNewsTag(@RequestBody WebNewsTag newsTag) {
        return Result.success(newsTagService.update(newsTag));
    }

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

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


}