mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 增肌小说发布列表查询接口
This commit is contained in:
parent
1151ed3f9f
commit
fa47081398
@ -1,22 +1,23 @@
|
|||||||
package io.github.xxyopen.novel.controller.author;
|
package io.github.xxyopen.novel.controller.author;
|
||||||
|
|
||||||
import io.github.xxyopen.novel.core.auth.UserHolder;
|
import io.github.xxyopen.novel.core.auth.UserHolder;
|
||||||
|
import io.github.xxyopen.novel.core.common.req.PageReqDto;
|
||||||
|
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
|
||||||
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.ApiRouterConsts;
|
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
|
||||||
import io.github.xxyopen.novel.dto.req.AuthorRegisterReqDto;
|
import io.github.xxyopen.novel.dto.req.AuthorRegisterReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
|
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
|
||||||
|
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
|
||||||
import io.github.xxyopen.novel.service.AuthorService;
|
import io.github.xxyopen.novel.service.AuthorService;
|
||||||
import io.github.xxyopen.novel.service.BookService;
|
import io.github.xxyopen.novel.service.BookService;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作家后台-作家模块 API 控制器
|
* 作家后台-作家模块 API 控制器
|
||||||
|
*
|
||||||
* @author xiongxiaoyang
|
* @author xiongxiaoyang
|
||||||
* @date 2022/5/23
|
* @date 2022/5/23
|
||||||
*/
|
*/
|
||||||
@ -46,6 +47,14 @@ public class AuthorController {
|
|||||||
return bookService.saveBook(dto);
|
return bookService.saveBook(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说发布列表查询接口
|
||||||
|
*/
|
||||||
|
@GetMapping("books")
|
||||||
|
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(PageReqDto dto) {
|
||||||
|
return bookService.listAuthorBooks(dto);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说章节发布接口
|
* 小说章节发布接口
|
||||||
*/
|
*/
|
||||||
|
@ -89,6 +89,8 @@ public class DatabaseConsts {
|
|||||||
|
|
||||||
public static final String COLUMN_CATEGORY_ID = "category_id";
|
public static final String COLUMN_CATEGORY_ID = "category_id";
|
||||||
|
|
||||||
|
public static final String AUTHOR_ID = "author_id";
|
||||||
|
|
||||||
public static final String COLUMN_VISIT_COUNT = "visit_count";
|
public static final String COLUMN_VISIT_COUNT = "visit_count";
|
||||||
|
|
||||||
public static final String COLUMN_LAST_CHAPTER_UPDATE_TIME = "last_chapter_update_time";
|
public static final String COLUMN_LAST_CHAPTER_UPDATE_TIME = "last_chapter_update_time";
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.github.xxyopen.novel.service;
|
package io.github.xxyopen.novel.service;
|
||||||
|
|
||||||
|
import io.github.xxyopen.novel.core.common.req.PageReqDto;
|
||||||
|
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
|
||||||
import io.github.xxyopen.novel.core.common.resp.RestResp;
|
import io.github.xxyopen.novel.core.common.resp.RestResp;
|
||||||
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
|
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
|
||||||
@ -128,32 +130,44 @@ public interface BookService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除评论
|
* 删除评论
|
||||||
* @param userId 评论用户ID
|
*
|
||||||
|
* @param userId 评论用户ID
|
||||||
* @param commentId 评论ID
|
* @param commentId 评论ID
|
||||||
* @return void
|
* @return void
|
||||||
* */
|
*/
|
||||||
RestResp<Void> deleteComment(Long userId, Long commentId);
|
RestResp<Void> deleteComment(Long userId, Long commentId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改评论
|
* 修改评论
|
||||||
* @param userId 用户ID
|
*
|
||||||
* @param id 评论ID
|
* @param userId 用户ID
|
||||||
|
* @param id 评论ID
|
||||||
* @param content 修改后的评论内容
|
* @param content 修改后的评论内容
|
||||||
* @return void
|
* @return void
|
||||||
* */
|
*/
|
||||||
RestResp<Void> updateComment(Long userId, Long id, String content);
|
RestResp<Void> updateComment(Long userId, Long id, String content);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说信息保存
|
* 小说信息保存
|
||||||
|
*
|
||||||
* @param dto 小说信息
|
* @param dto 小说信息
|
||||||
* @return void
|
* @return void
|
||||||
* */
|
*/
|
||||||
RestResp<Void> saveBook(BookAddReqDto dto);
|
RestResp<Void> saveBook(BookAddReqDto dto);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说章节信息保存
|
* 小说章节信息保存
|
||||||
|
*
|
||||||
* @param dto 章节信息
|
* @param dto 章节信息
|
||||||
* @return void
|
* @return void
|
||||||
* */
|
*/
|
||||||
RestResp<Void> saveBookChapter(ChapterAddReqDto dto);
|
RestResp<Void> saveBookChapter(ChapterAddReqDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询作家发布小说列表
|
||||||
|
*
|
||||||
|
* @param dto 分页请求参数
|
||||||
|
* @return 小说分页列表数据
|
||||||
|
*/
|
||||||
|
RestResp<PageRespDto<BookInfoRespDto>> listAuthorBooks(PageReqDto dto);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.github.xxyopen.novel.core.auth.UserHolder;
|
import io.github.xxyopen.novel.core.auth.UserHolder;
|
||||||
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
|
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
|
||||||
|
import io.github.xxyopen.novel.core.common.req.PageReqDto;
|
||||||
|
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
|
||||||
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.core.constant.DatabaseConsts;
|
||||||
import io.github.xxyopen.novel.dao.entity.*;
|
import io.github.xxyopen.novel.dao.entity.*;
|
||||||
@ -199,9 +203,9 @@ public class BookServiceImpl implements BookService {
|
|||||||
public RestResp<Void> saveComment(UserCommentReqDto dto) {
|
public RestResp<Void> saveComment(UserCommentReqDto dto) {
|
||||||
// 校验用户是否已发表评论
|
// 校验用户是否已发表评论
|
||||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,dto.getUserId())
|
queryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, dto.getUserId())
|
||||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_BOOK_ID,dto.getBookId());
|
.eq(DatabaseConsts.BookCommentTable.COLUMN_BOOK_ID, dto.getBookId());
|
||||||
if(bookCommentMapper.selectCount(queryWrapper) > 0){
|
if (bookCommentMapper.selectCount(queryWrapper) > 0) {
|
||||||
// 用户已发表评论
|
// 用户已发表评论
|
||||||
return RestResp.fail(ErrorCodeEnum.USER_COMMENTED);
|
return RestResp.fail(ErrorCodeEnum.USER_COMMENTED);
|
||||||
}
|
}
|
||||||
@ -254,8 +258,8 @@ public class BookServiceImpl implements BookService {
|
|||||||
public RestResp<Void> deleteComment(Long userId, Long commentId) {
|
public RestResp<Void> deleteComment(Long userId, Long commentId) {
|
||||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), commentId)
|
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), commentId)
|
||||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,userId);
|
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, userId);
|
||||||
bookCommentMapper.delete(queryWrapper);
|
bookCommentMapper.delete(queryWrapper);
|
||||||
return RestResp.ok();
|
return RestResp.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,10 +267,10 @@ public class BookServiceImpl implements BookService {
|
|||||||
public RestResp<Void> updateComment(Long userId, Long id, String content) {
|
public RestResp<Void> updateComment(Long userId, Long id, String content) {
|
||||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), id)
|
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), id)
|
||||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,userId);
|
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, userId);
|
||||||
BookComment bookComment = new BookComment();
|
BookComment bookComment = new BookComment();
|
||||||
bookComment.setCommentContent(content);
|
bookComment.setCommentContent(content);
|
||||||
bookCommentMapper.update(bookComment,queryWrapper);
|
bookCommentMapper.update(bookComment, queryWrapper);
|
||||||
return RestResp.ok();
|
return RestResp.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,11 +304,11 @@ public class BookServiceImpl implements BookService {
|
|||||||
// a) 查询最新章节号
|
// a) 查询最新章节号
|
||||||
int chapterNum = 0;
|
int chapterNum = 0;
|
||||||
QueryWrapper<BookChapter> chapterQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<BookChapter> chapterQueryWrapper = new QueryWrapper<>();
|
||||||
chapterQueryWrapper.eq(DatabaseConsts.BookChapterTable.COLUMN_BOOK_ID,dto.getBookId())
|
chapterQueryWrapper.eq(DatabaseConsts.BookChapterTable.COLUMN_BOOK_ID, dto.getBookId())
|
||||||
.orderByDesc(DatabaseConsts.BookChapterTable.COLUMN_CHAPTER_NUM)
|
.orderByDesc(DatabaseConsts.BookChapterTable.COLUMN_CHAPTER_NUM)
|
||||||
.last(DatabaseConsts.SqlEnum.LIMIT_1.getSql());
|
.last(DatabaseConsts.SqlEnum.LIMIT_1.getSql());
|
||||||
BookChapter bookChapter = bookChapterMapper.selectOne(chapterQueryWrapper);
|
BookChapter bookChapter = bookChapterMapper.selectOne(chapterQueryWrapper);
|
||||||
if(Objects.nonNull(bookChapter)){
|
if (Objects.nonNull(bookChapter)) {
|
||||||
chapterNum = bookChapter.getChapterNum() + 1;
|
chapterNum = bookChapter.getChapterNum() + 1;
|
||||||
}
|
}
|
||||||
// b) 设置章节相关信息并保存
|
// b) 设置章节相关信息并保存
|
||||||
@ -344,9 +348,31 @@ public class BookServiceImpl implements BookService {
|
|||||||
return RestResp.ok();
|
return RestResp.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RestResp<PageRespDto<BookInfoRespDto>> listAuthorBooks(PageReqDto dto) {
|
||||||
|
IPage<BookInfo> page = new Page<>();
|
||||||
|
page.setCurrent(dto.getPageNum());
|
||||||
|
page.setSize(dto.getPageSize());
|
||||||
|
QueryWrapper<BookInfo> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq(DatabaseConsts.BookTable.AUTHOR_ID, UserHolder.getAuthorId())
|
||||||
|
.orderByDesc(DatabaseConsts.CommonColumnEnum.CREATE_TIME.getName());
|
||||||
|
IPage<BookInfo> bookInfoPage = bookInfoMapper.selectPage(page, queryWrapper);
|
||||||
|
return RestResp.ok(PageRespDto.of(dto.getPageNum(), dto.getPageSize(), page.getTotal(),
|
||||||
|
bookInfoPage.getRecords().stream().map(v -> BookInfoRespDto.builder()
|
||||||
|
.id(v.getId())
|
||||||
|
.bookName(v.getBookName())
|
||||||
|
.picUrl(v.getPicUrl())
|
||||||
|
.categoryId(v.getCategoryId())
|
||||||
|
.categoryName(v.getCategoryName())
|
||||||
|
.wordCount(v.getWordCount())
|
||||||
|
.visitCount(v.getVisitCount())
|
||||||
|
.lastChapterName(v.getLastChapterName())
|
||||||
|
.build()).toList()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
||||||
log.debug("userId:{}",UserHolder.getUserId());
|
log.debug("userId:{}", UserHolder.getUserId());
|
||||||
// 查询章节信息
|
// 查询章节信息
|
||||||
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(chapterId);
|
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(chapterId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user