package com.fdkankan.manage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.response.ResultData;
import com.fdkankan.manage.entity.News;
import com.fdkankan.manage.service.INewsService;
import com.fdkankan.manage.vo.BaseParamVO;
import com.fdkankan.manage.vo.NewsDisplayParamVO;
import com.fdkankan.manage.vo.NewsPublicParamVO;
import com.fdkankan.manage.vo.NewsPutTopParamVO;
import com.fdkankan.manage.vo.PageNewsParamVO;
import com.fdkankan.manage.vo.PageNewsVO;
import com.fdkankan.manage.vo.SaveNewsParamVO;
import com.fdkankan.manage.vo.UpdateNewsParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/service/manage/news")
public class NewsController extends BaseController {

    @Autowired
    private INewsService newsService;

    /**
     * 新闻列表
     * @param param
     * @return
     */
    @PostMapping("/pageNews")
    public Page<PageNewsVO> pageNews(@RequestBody PageNewsParamVO param){
        return newsService.pageNews(param);
    }

    /**
     * 新闻列表
     * @param param
     * @return
     */
    @PostMapping("/publicNews")
    public ResultData publicNews(@RequestBody @Validated NewsPublicParamVO param){
        return newsService.publicNews(this.getUserId(), param);
    }

    /**
     * 修改是否显示
     * @param param
     * @return
     */
    @PostMapping("/display")
    public ResultData display(@RequestBody @Validated NewsDisplayParamVO param){
        return newsService.display(this.getUserId(), param);
    }

    /**
     * 修改是否置顶
     * @param param
     * @return
     */
    @PostMapping("/putTop")
    public ResultData putTop(@RequestBody @Validated NewsPutTopParamVO param){
        return newsService.putTop(this.getUserId(), param);
    }

    /**
     * 修改是否置顶
     * @param param
     * @return
     */
    @PostMapping("/delete")
    public ResultData delete(@RequestBody @Validated BaseParamVO param){
        return newsService.delete(this.getUserId(), param);
    }

    /**
     * 获取新闻详情
     * @param param
     * @return
     */
    @PostMapping("/getNewsDetail")
    public News getNewsDetail(@RequestBody @Validated BaseParamVO param){
        return newsService.getNewsDetail(param);
    }

    /**
     * 保存
     * @param param
     * @return
     */
    @PostMapping("/addNews")
    public ResultData addNews(@RequestBody @Validated SaveNewsParamVO param){
        return newsService.addNews(this.getUserId(), param);
    }

    /**
     * 保存
     * @param param
     * @return
     */
    @PostMapping("/updateNews")
    public ResultData updateNews(@RequestBody @Validated UpdateNewsParamVO param){
        return newsService.updateNews(this.getUserId(), param);
    }

}

