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

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/front/news")
public class FrontNewsController {

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

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

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

    @GetMapping("/tag/{tagId}")
    @ApiOperation(value = "依据tagId获取 News", response = Result.class)
    public Result selectFrontByTagId(@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));
    }

}