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