feat: 增肌小说发布列表查询接口

This commit is contained in:
xiongxiaoyang 2022-05-29 12:31:10 +08:00
parent 1151ed3f9f
commit fa47081398
4 changed files with 72 additions and 21 deletions

View File

@ -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);
}
/**
* 小说章节发布接口
*/

View File

@ -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";

View File

@ -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 commentId 评论ID
* @return void
* */
*/
RestResp<Void> deleteComment(Long userId, Long commentId);
/**
* 修改评论
*
* @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);
}

View File

@ -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.*;
@ -344,6 +348,28 @@ 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());