package com.rongyichuang.news.resolver;
|
|
import com.rongyichuang.news.dto.NewsInput;
|
import com.rongyichuang.news.dto.NewsResponse;
|
import com.rongyichuang.news.service.NewsService;
|
import com.rongyichuang.common.dto.PageRequest;
|
import com.rongyichuang.common.dto.PageResponse;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.graphql.data.method.annotation.Argument;
|
import org.springframework.graphql.data.method.annotation.MutationMapping;
|
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
import org.springframework.stereotype.Controller;
|
|
@Controller
|
public class NewsResolver {
|
|
@Autowired
|
private NewsService newsService;
|
|
/**
|
* 分页查询新闻列表(管理端)
|
*/
|
@QueryMapping
|
public PageResponse<NewsResponse> newsList(@Argument int page, @Argument int size, @Argument String title, @Argument Integer state) {
|
PageRequest pageRequest = new PageRequest(page, size);
|
return newsService.findNews(pageRequest, title, state);
|
}
|
|
/**
|
* 获取新闻详情(管理端)
|
*/
|
@QueryMapping
|
public NewsResponse news(@Argument Long id) {
|
return newsService.findById(id);
|
}
|
|
/**
|
* 获取已发布的新闻详情(前端展示)
|
*/
|
@QueryMapping
|
public NewsResponse publishedNews(@Argument Long id) {
|
return newsService.findPublishedNewsById(id);
|
}
|
|
/**
|
* 获取已发布的新闻列表(前端展示)
|
*/
|
@QueryMapping
|
public PageResponse<NewsResponse> publishedNewsList(@Argument int page, @Argument int size) {
|
PageRequest pageRequest = new PageRequest(page, size);
|
return newsService.findPublishedNews(pageRequest);
|
}
|
|
/**
|
* 保存新闻
|
*/
|
@MutationMapping
|
public NewsResponse saveNews(@Argument NewsInput input) {
|
return newsService.saveNews(input);
|
}
|
|
/**
|
* 删除新闻
|
*/
|
@MutationMapping
|
public Boolean deleteNews(@Argument Long id) {
|
return newsService.deleteNews(id);
|
}
|
|
/**
|
* 更新新闻状态
|
*/
|
@MutationMapping
|
public Boolean updateNewsState(@Argument Long id, @Argument Integer state) {
|
return newsService.updateNewsState(id, state);
|
}
|
}
|