mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 新增新闻信息查询接口
This commit is contained in:
parent
06ef610424
commit
2271eac6c0
@ -27,39 +27,39 @@ public class BookController {
|
||||
|
||||
/**
|
||||
* 小说搜索接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("search")
|
||||
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(BookSearchReqDto condition){
|
||||
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(BookSearchReqDto condition) {
|
||||
return bookService.searchBooks(condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说信息查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("{bookId}")
|
||||
public RestResp<BookInfoRespDto> getBookById(@PathVariable("bookId") Long bookId){
|
||||
public RestResp<BookInfoRespDto> getBookById(@PathVariable("bookId") Long bookId) {
|
||||
return bookService.getBookById(bookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加小说点击量接口
|
||||
* */
|
||||
*/
|
||||
@PostMapping("visit")
|
||||
public RestResp<Void> addVisitCount(Long bookId){
|
||||
public RestResp<Void> addVisitCount(Long bookId) {
|
||||
return bookService.addVisitCount(bookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说最新章节相关信息查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("lastChapterAbout")
|
||||
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId){
|
||||
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId) {
|
||||
return bookService.getLastChapterAbout(bookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说推荐列表查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("recList")
|
||||
public RestResp<List<BookInfoRespDto>> listRecBooks(Long bookId) throws NoSuchAlgorithmException {
|
||||
return bookService.listRecBooks(bookId);
|
||||
@ -67,59 +67,58 @@ public class BookController {
|
||||
|
||||
/**
|
||||
* 小说章节列表查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("chapterList")
|
||||
public RestResp<List<BookChapterRespDto>> listChapters(Long bookId){
|
||||
public RestResp<List<BookChapterRespDto>> listChapters(Long bookId) {
|
||||
return bookService.listChapters(bookId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说内容相关信息查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("content/{chapterId}")
|
||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId){
|
||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId) {
|
||||
return bookService.getBookContentAbout(chapterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上一章节ID接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("preChapterId/{chapterId}")
|
||||
public RestResp<Long> getPreChapterId(@PathVariable("chapterId") Long chapterId){
|
||||
public RestResp<Long> getPreChapterId(@PathVariable("chapterId") Long chapterId) {
|
||||
return bookService.getPreChapterId(chapterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一章节ID接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("nextChapterId/{chapterId}")
|
||||
public RestResp<Long> nextChapterId(@PathVariable("chapterId") Long chapterId){
|
||||
public RestResp<Long> nextChapterId(@PathVariable("chapterId") Long chapterId) {
|
||||
return bookService.nextChapterId(chapterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说点击榜查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("visitRank")
|
||||
public RestResp<List<BookRankRespDto>> listVisitRankBooks(){
|
||||
public RestResp<List<BookRankRespDto>> listVisitRankBooks() {
|
||||
return bookService.listVisitRankBooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说新书榜查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("newestRank")
|
||||
public RestResp<List<BookRankRespDto>> listNewestRankBooks(){
|
||||
public RestResp<List<BookRankRespDto>> listNewestRankBooks() {
|
||||
return bookService.listNewestRankBooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* 小说更新榜查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("updateRank")
|
||||
public RestResp<List<BookRankRespDto>> listUpdateRankBooks(){
|
||||
public RestResp<List<BookRankRespDto>> listUpdateRankBooks() {
|
||||
return bookService.listUpdateRankBooks();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -27,17 +27,17 @@ public class HomeController {
|
||||
|
||||
/**
|
||||
* 首页小说推荐查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("books")
|
||||
public RestResp<List<HomeBookRespDto>> listHomeBooks(){
|
||||
public RestResp<List<HomeBookRespDto>> listHomeBooks() {
|
||||
return homeService.listHomeBooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页友情链接列表查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("friendLinks")
|
||||
public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks(){
|
||||
public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
|
||||
return homeService.listHomeFriendLinks();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
|
||||
import io.github.xxyopen.novel.service.NewsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -26,9 +27,17 @@ public class NewsController {
|
||||
|
||||
/**
|
||||
* 最新新闻列表查询接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("latestList")
|
||||
public RestResp<List<NewsInfoRespDto>> listLatestNews(){
|
||||
public RestResp<List<NewsInfoRespDto>> listLatestNews() {
|
||||
return newsService.listLatestNews();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻信息查询接口
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public RestResp<NewsInfoRespDto> getNews(@PathVariable Long id) {
|
||||
return newsService.getNews(id);
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ public class DatabaseConsts {
|
||||
|
||||
CATEGORY_ID("category_id"),
|
||||
VISIT_COUNT("visit_count"),
|
||||
LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time")
|
||||
;
|
||||
LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time");
|
||||
|
||||
private String name;
|
||||
|
||||
@ -43,8 +42,7 @@ public class DatabaseConsts {
|
||||
|
||||
BOOK_ID("book_id"),
|
||||
CHAPTER_NUM("chapter_num"),
|
||||
LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time")
|
||||
;
|
||||
LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time");
|
||||
|
||||
private String name;
|
||||
|
||||
@ -64,8 +62,27 @@ public class DatabaseConsts {
|
||||
@Getter
|
||||
public enum ColumnEnum {
|
||||
|
||||
CHAPTER_ID("chapter_id")
|
||||
;
|
||||
CHAPTER_ID("chapter_id");
|
||||
|
||||
private String name;
|
||||
|
||||
ColumnEnum(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻内容表
|
||||
*/
|
||||
public static class NewsContentTable {
|
||||
|
||||
@Getter
|
||||
public enum ColumnEnum {
|
||||
|
||||
NEWS_ID("news_id");
|
||||
|
||||
private String name;
|
||||
|
||||
@ -79,9 +96,9 @@ public class DatabaseConsts {
|
||||
|
||||
/**
|
||||
* 通用列枚举类
|
||||
* */
|
||||
*/
|
||||
@Getter
|
||||
public enum CommonColumnEnum{
|
||||
public enum CommonColumnEnum {
|
||||
|
||||
ID("id"),
|
||||
SORT("sort"),
|
||||
@ -90,7 +107,7 @@ public class DatabaseConsts {
|
||||
|
||||
private String name;
|
||||
|
||||
CommonColumnEnum(String name){
|
||||
CommonColumnEnum(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -99,15 +116,14 @@ public class DatabaseConsts {
|
||||
|
||||
/**
|
||||
* SQL语句枚举类
|
||||
* */
|
||||
*/
|
||||
@Getter
|
||||
public enum SqlEnum {
|
||||
|
||||
LIMIT_1("limit 1"),
|
||||
LIMIT_2("limit 2"),
|
||||
LIMIT_30("limit 30"),
|
||||
LIMIT_500("limit 500")
|
||||
;
|
||||
LIMIT_500("limit 500");
|
||||
|
||||
private String sql;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.xxyopen.novel.dto.resp;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -12,6 +13,7 @@ import java.time.LocalDateTime;
|
||||
* @date 2022/5/14
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class NewsInfoRespDto {
|
||||
|
||||
/**
|
||||
@ -45,5 +47,10 @@ public class NewsInfoRespDto {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 新闻内容
|
||||
* */
|
||||
private String content;
|
||||
|
||||
|
||||
}
|
||||
|
@ -34,16 +34,14 @@ public class NewsCacheManager {
|
||||
QueryWrapper<NewsInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.orderByDesc(DatabaseConsts.CommonColumnEnum.CREATE_TIME.getName())
|
||||
.last(DatabaseConsts.SqlEnum.LIMIT_2.getSql());
|
||||
return newsInfoMapper.selectList(queryWrapper).stream().map(v -> {
|
||||
NewsInfoRespDto respDto = new NewsInfoRespDto();
|
||||
respDto.setId(v.getId());
|
||||
respDto.setCategoryId(v.getCategoryId());
|
||||
respDto.setCategoryName(v.getCategoryName());
|
||||
respDto.setTitle(v.getTitle());
|
||||
respDto.setSourceName(v.getSourceName());
|
||||
respDto.setUpdateTime(v.getUpdateTime());
|
||||
return respDto;
|
||||
}).toList();
|
||||
return newsInfoMapper.selectList(queryWrapper).stream().map(v -> NewsInfoRespDto.builder()
|
||||
.id(v.getId())
|
||||
.categoryId(v.getCategoryId())
|
||||
.categoryName(v.getCategoryName())
|
||||
.title(v.getTitle())
|
||||
.sourceName(v.getSourceName())
|
||||
.updateTime(v.getUpdateTime())
|
||||
.build()).toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,4 +18,11 @@ public interface NewsService {
|
||||
* @return 新闻列表
|
||||
* */
|
||||
RestResp<List<NewsInfoRespDto>> listLatestNews();
|
||||
|
||||
/**
|
||||
* 新闻信息查询
|
||||
* @param id 新闻ID
|
||||
* @return 新闻信息
|
||||
* */
|
||||
RestResp<NewsInfoRespDto> getNews(Long id);
|
||||
}
|
||||
|
@ -1,6 +1,12 @@
|
||||
package io.github.xxyopen.novel.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.github.xxyopen.novel.core.common.resp.RestResp;
|
||||
import io.github.xxyopen.novel.core.constant.DatabaseConsts;
|
||||
import io.github.xxyopen.novel.dao.entity.NewsContent;
|
||||
import io.github.xxyopen.novel.dao.entity.NewsInfo;
|
||||
import io.github.xxyopen.novel.dao.mapper.NewsContentMapper;
|
||||
import io.github.xxyopen.novel.dao.mapper.NewsInfoMapper;
|
||||
import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
|
||||
import io.github.xxyopen.novel.manager.NewsCacheManager;
|
||||
import io.github.xxyopen.novel.service.NewsService;
|
||||
@ -21,8 +27,27 @@ public class NewsServiceImpl implements NewsService {
|
||||
|
||||
private final NewsCacheManager newsCacheManager;
|
||||
|
||||
private final NewsInfoMapper newsInfoMapper;
|
||||
|
||||
private final NewsContentMapper newsContentMapper;
|
||||
|
||||
@Override
|
||||
public RestResp<List<NewsInfoRespDto>> listLatestNews() {
|
||||
return RestResp.ok(newsCacheManager.listLatestNews());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<NewsInfoRespDto> getNews(Long id) {
|
||||
NewsInfo newsInfo = newsInfoMapper.selectById(id);
|
||||
QueryWrapper<NewsContent> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(DatabaseConsts.NewsContentTable.ColumnEnum.NEWS_ID.getName(), id)
|
||||
.last(DatabaseConsts.SqlEnum.LIMIT_1.getSql());
|
||||
NewsContent newsContent = newsContentMapper.selectOne(queryWrapper);
|
||||
return RestResp.ok(NewsInfoRespDto.builder()
|
||||
.title(newsInfo.getTitle())
|
||||
.sourceName(newsInfo.getSourceName())
|
||||
.updateTime(newsInfo.getUpdateTime())
|
||||
.content(newsContent.getContent())
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user