package com.hc.gpweb.controller.api;

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

import javax.validation.Valid;


/**
 * 新闻操作记录表，比如转发，点评(NewsHistory)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:11
 */

@RestController
@RequestMapping("/api/newsHistory")
public class NewsHistoryController {

    /**
     * 服务对象
     */
    private final WebNewsHistoryService newsHistoryService;

    public NewsHistoryController(WebNewsHistoryService newsHistoryService) {
        this.newsHistoryService = newsHistoryService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 NewsHistory", response = Result.class)
    public Result addNewsHistory(@Valid @RequestBody WebNewsHistory newsHistory) {
        return Result.success(newsHistoryService.insert(newsHistory));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 NewsHistory", response = Result.class)
    public Result updateNewsHistory(@RequestBody WebNewsHistory newsHistory) {
        return Result.success(newsHistoryService.update(newsHistory));
    }

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

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


}