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

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

import javax.validation.Valid;


/**
 * 新闻标签表(NewsTag)表控制层
 *
 * @author java
 * @since 2020-11-20 12:52:34
 */

@RestController
@RequestMapping("/new/api/back/newsTag")
public class BackNewsTagController {

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


    public BackNewsTagController(NewsTagService newsTagService) {
        this.newsTagService = newsTagService;
    }

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

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

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

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

    @GetMapping("/list")
    @ApiOperation(value = "获取 NewsTag列表", response = Result.class)
    public Result listBackNewsTag() {
        return Result.success(newsTagService.queryAll());
    }

}