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;
|
||||
|
||||
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.constant.ApiRouterConsts;
|
||||
import io.github.xxyopen.novel.dto.req.AuthorRegisterReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
||||
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.BookService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 作家后台-作家模块 API 控制器
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/23
|
||||
*/
|
||||
@ -46,6 +47,14 @@ public class AuthorController {
|
||||
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 AUTHOR_ID = "author_id";
|
||||
|
||||
public static final String COLUMN_VISIT_COUNT = "visit_count";
|
||||
|
||||
public static final String COLUMN_LAST_CHAPTER_UPDATE_TIME = "last_chapter_update_time";
|
||||
|
@ -1,5 +1,7 @@
|
||||
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.dto.req.BookAddReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
|
||||
@ -128,32 +130,44 @@ public interface BookService {
|
||||
|
||||
/**
|
||||
* 删除评论
|
||||
* @param userId 评论用户ID
|
||||
*
|
||||
* @param userId 评论用户ID
|
||||
* @param commentId 评论ID
|
||||
* @return void
|
||||
* */
|
||||
*/
|
||||
RestResp<Void> deleteComment(Long userId, Long commentId);
|
||||
|
||||
/**
|
||||
* 修改评论
|
||||
* @param userId 用户ID
|
||||
* @param id 评论ID
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param id 评论ID
|
||||
* @param content 修改后的评论内容
|
||||
* @return void
|
||||
* */
|
||||
*/
|
||||
RestResp<Void> updateComment(Long userId, Long id, String content);
|
||||
|
||||
/**
|
||||
* 小说信息保存
|
||||
*
|
||||
* @param dto 小说信息
|
||||
* @return void
|
||||
* */
|
||||
*/
|
||||
RestResp<Void> saveBook(BookAddReqDto dto);
|
||||
|
||||
/**
|
||||
* 小说章节信息保存
|
||||
*
|
||||
* @param dto 章节信息
|
||||
* @return void
|
||||
* */
|
||||
*/
|
||||
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;
|
||||
|
||||
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.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.constant.DatabaseConsts;
|
||||
import io.github.xxyopen.novel.dao.entity.*;
|
||||
@ -199,9 +203,9 @@ public class BookServiceImpl implements BookService {
|
||||
public RestResp<Void> saveComment(UserCommentReqDto dto) {
|
||||
// 校验用户是否已发表评论
|
||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,dto.getUserId())
|
||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_BOOK_ID,dto.getBookId());
|
||||
if(bookCommentMapper.selectCount(queryWrapper) > 0){
|
||||
queryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, dto.getUserId())
|
||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_BOOK_ID, dto.getBookId());
|
||||
if (bookCommentMapper.selectCount(queryWrapper) > 0) {
|
||||
// 用户已发表评论
|
||||
return RestResp.fail(ErrorCodeEnum.USER_COMMENTED);
|
||||
}
|
||||
@ -254,8 +258,8 @@ public class BookServiceImpl implements BookService {
|
||||
public RestResp<Void> deleteComment(Long userId, Long commentId) {
|
||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), commentId)
|
||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,userId);
|
||||
bookCommentMapper.delete(queryWrapper);
|
||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, userId);
|
||||
bookCommentMapper.delete(queryWrapper);
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@ -263,10 +267,10 @@ public class BookServiceImpl implements BookService {
|
||||
public RestResp<Void> updateComment(Long userId, Long id, String content) {
|
||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||
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.setCommentContent(content);
|
||||
bookCommentMapper.update(bookComment,queryWrapper);
|
||||
bookCommentMapper.update(bookComment, queryWrapper);
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@ -300,11 +304,11 @@ public class BookServiceImpl implements BookService {
|
||||
// a) 查询最新章节号
|
||||
int chapterNum = 0;
|
||||
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)
|
||||
.last(DatabaseConsts.SqlEnum.LIMIT_1.getSql());
|
||||
BookChapter bookChapter = bookChapterMapper.selectOne(chapterQueryWrapper);
|
||||
if(Objects.nonNull(bookChapter)){
|
||||
if (Objects.nonNull(bookChapter)) {
|
||||
chapterNum = bookChapter.getChapterNum() + 1;
|
||||
}
|
||||
// b) 设置章节相关信息并保存
|
||||
@ -344,9 +348,31 @@ public class BookServiceImpl implements BookService {
|
||||
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
|
||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
||||
log.debug("userId:{}",UserHolder.getUserId());
|
||||
log.debug("userId:{}", UserHolder.getUserId());
|
||||
// 查询章节信息
|
||||
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(chapterId);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user