package com.yc.education.controller;

import com.github.pagehelper.PageInfo;
import com.yc.education.model.News;
import com.yc.education.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 新闻Controller 层
 *
 * @author YaoShiHang
 * @Date 15:58 2018-04-13
 */
@RestController
public class NewsController {

    @Autowired
    private NewsService newsService;


    @RequestMapping(value = "newspage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public PageInfo<News> listNews(@RequestParam(required = false, defaultValue = "0") int page,
                                   @RequestParam(required = false, defaultValue = "1") int rows) {
        List<News> newsList = newsService.listAll(page, rows);
        return new PageInfo<News>(newsList);
    }

    @RequestMapping(value = "getnews", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public News getNew(long id){
        return newsService.selectByKey(id);
    }

}
