peng
2025-11-06 c4938f6f4e839890b032c75c7a57333a6a9157a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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);
    }
}