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

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


/**
 * 新闻表
 * (News)表控制层
 *
 * @author java
 * @since 2020-11-20 11:48:39
 */

@RestController
@RequestMapping("/new/api/app/news")
public class AppNewsController {

    /**
     * 服务对象
     */
    private final NewsService newsService;

    public AppNewsController(NewsService newsService) {
        this.newsService = newsService;
    }

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

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

    @GetMapping("/tag/{tagId}")
    @ApiOperation(value = "依据tagId获取 News", response = Result.class)
    public Result selectAppByTagId(@ApiParam(value = "新闻标签id") @PathVariable("tagId") Integer tagId,
                                   @RequestParam(defaultValue = "0") Integer page,
                                   @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(this.newsService.queryListByTagId(tagId, page, size));
    }


}