package com.hc.gpweb.controller.api;

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

import javax.validation.Valid;


/**
 * 新闻标签，新闻对应表(NewsTagCollection)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:12
 */

@RestController
@RequestMapping("/api/newsTagCollection")
public class NewsTagCollectionController {

    /**
     * 服务对象
     */
    private final WebNewsTagCollectionService newsTagCollectionService;

    public NewsTagCollectionController(WebNewsTagCollectionService newsTagCollectionService) {
        this.newsTagCollectionService = newsTagCollectionService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 NewsTagCollection", response = Result.class)
    public Result addNewsTagCollection(@Valid @RequestBody WebNewsTagCollection newsTagCollection) {
        return Result.success(newsTagCollectionService.insert(newsTagCollection));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 NewsTagCollection", response = Result.class)
    public Result updateNewsTagCollection(@RequestBody WebNewsTagCollection newsTagCollection) {
        return Result.success(newsTagCollectionService.update(newsTagCollection));
    }

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

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


}