feat: 集成 springdoc-openapi 自动生成 API 文档

This commit is contained in:
xiongxiaoyang 2022-06-27 11:17:49 +08:00
parent c572650107
commit dec50ab0a0
33 changed files with 264 additions and 28 deletions

19
pom.xml
View File

@ -24,6 +24,7 @@
<shardingsphere-jdbc.version>5.1.1</shardingsphere-jdbc.version>
<redisson.version>3.17.4</redisson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -174,6 +175,13 @@
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- OpenAPI 3 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0-M4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -240,6 +248,17 @@
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>sonatype-nexus-snapshots-2</id>
<name>Sonatype Nexus Snapshots 2</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>

View File

@ -1,5 +1,12 @@
package io.github.xxyopen.novel;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
@ -13,10 +20,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
import java.util.Map;
@OpenAPIDefinition(info = @Info(title = "novel 项目接口文档", version = "v3.2.0", license = @License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0")))
@SecurityScheme(type = SecuritySchemeType.APIKEY, in = SecuritySchemeIn.HEADER, name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME, description = "登录 token")
@SpringBootApplication
@MapperScan("io.github.xxyopen.novel.dao.mapper")
@EnableCaching

View File

@ -5,6 +5,7 @@ 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.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.dto.req.AuthorRegisterReqDto;
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
@ -12,8 +13,13 @@ import io.github.xxyopen.novel.dto.resp.BookChapterRespDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.AuthorService;
import io.github.xxyopen.novel.service.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
/**
@ -22,6 +28,8 @@ import org.springframework.web.bind.annotation.*;
* @author xiongxiaoyang
* @date 2022/5/23
*/
@Tag(name = "author", description = "作家后台-作者模块")
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@RestController
@RequestMapping(ApiRouterConsts.API_AUTHOR_URL_PREFIX)
@RequiredArgsConstructor
@ -34,6 +42,7 @@ public class AuthorController {
/**
* 作家注册接口
*/
@Operation(description = "作家注册接口")
@PostMapping("register")
public RestResp<Void> register(@Valid @RequestBody AuthorRegisterReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -43,6 +52,7 @@ public class AuthorController {
/**
* 查询作家状态接口
*/
@Operation(description = "作家状态查询接口")
@GetMapping("status")
public RestResp<Integer> getStatus() {
return authorService.getStatus(UserHolder.getUserId());
@ -51,6 +61,7 @@ public class AuthorController {
/**
* 小说发布接口
*/
@Operation(description = "小说发布接口")
@PostMapping("book")
public RestResp<Void> publishBook(@Valid @RequestBody BookAddReqDto dto) {
return bookService.saveBook(dto);
@ -59,16 +70,18 @@ public class AuthorController {
/**
* 小说发布列表查询接口
*/
@Operation(description = "小说发布列表查询接口")
@GetMapping("books")
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(PageReqDto dto) {
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(@ParameterObject PageReqDto dto) {
return bookService.listAuthorBooks(dto);
}
/**
* 小说章节发布接口
*/
@Operation(description = "小说章节发布接口")
@PostMapping("book/chapter/{bookId}")
public RestResp<Void> publishBookChapter(@PathVariable("bookId") Long bookId, @Valid @RequestBody ChapterAddReqDto dto) {
public RestResp<Void> publishBookChapter(@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId, @Valid @RequestBody ChapterAddReqDto dto) {
dto.setBookId(bookId);
return bookService.saveBookChapter(dto);
}
@ -76,8 +89,9 @@ public class AuthorController {
/**
* 小说章节发布列表查询接口
*/
@Operation(description = "小说章节发布列表查询接口")
@GetMapping("book/chapters/{bookId}")
public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(@PathVariable("bookId") Long bookId, PageReqDto dto) {
public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId, PageReqDto dto) {
return bookService.listBookChapters(bookId, dto);
}

View File

@ -4,6 +4,9 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.resp.*;
import io.github.xxyopen.novel.service.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@ -16,6 +19,7 @@ import java.util.List;
* @author xiongxiaoyang
* @date 2022/5/14
*/
@Tag(name = "book", description = "前台门户-小说模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_BOOK_URL_PREFIX)
@RequiredArgsConstructor
@ -26,78 +30,88 @@ public class BookController {
/**
* 小说分类列表查询接口
*/
@Operation(description = "小说分类列表查询接口")
@GetMapping("category/list")
public RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection) {
public RestResp<List<BookCategoryRespDto>> listCategory(@Parameter(description = "作品方向",required = true) Integer workDirection) {
return bookService.listCategory(workDirection);
}
/**
* 小说信息查询接口
*/
@Operation(description = "小说信息查询接口")
@GetMapping("{id}")
public RestResp<BookInfoRespDto> getBookById(@PathVariable("id") Long bookId) {
public RestResp<BookInfoRespDto> getBookById(@Parameter(description = "小说 ID") @PathVariable("id") Long bookId) {
return bookService.getBookById(bookId);
}
/**
* 增加小说点击量接口
*/
@Operation(description = "增加小说点击量接口")
@PostMapping("visit")
public RestResp<Void> addVisitCount(Long bookId) {
public RestResp<Void> addVisitCount(@Parameter(description = "小说ID") Long bookId) {
return bookService.addVisitCount(bookId);
}
/**
* 小说最新章节相关信息查询接口
*/
@Operation(description = "小说最新章节相关信息查询接口")
@GetMapping("last_chapter/about")
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId) {
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(@Parameter(description = "小说ID") Long bookId) {
return bookService.getLastChapterAbout(bookId);
}
/**
* 小说推荐列表查询接口
*/
@Operation(description = "小说推荐列表查询接口")
@GetMapping("rec_list")
public RestResp<List<BookInfoRespDto>> listRecBooks(Long bookId) throws NoSuchAlgorithmException {
public RestResp<List<BookInfoRespDto>> listRecBooks(@Parameter(description = "小说ID") Long bookId) throws NoSuchAlgorithmException {
return bookService.listRecBooks(bookId);
}
/**
* 小说章节列表查询接口
*/
@Operation(description = "小说章节列表查询接口")
@GetMapping("chapter/list")
public RestResp<List<BookChapterRespDto>> listChapters(Long bookId) {
public RestResp<List<BookChapterRespDto>> listChapters(@Parameter(description = "小说ID") Long bookId) {
return bookService.listChapters(bookId);
}
/**
* 小说内容相关信息查询接口
*/
@Operation(description = "小说内容相关信息查询接口")
@GetMapping("content/{chapterId}")
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId) {
public RestResp<BookContentAboutRespDto> getBookContentAbout(@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getBookContentAbout(chapterId);
}
/**
* 获取上一章节ID接口
*/
@Operation(description = "获取上一章节ID接口")
@GetMapping("pre_chapter_id/{chapterId}")
public RestResp<Long> getPreChapterId(@PathVariable("chapterId") Long chapterId) {
public RestResp<Long> getPreChapterId(@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getPreChapterId(chapterId);
}
/**
* 获取下一章节ID接口
*/
@Operation(description = "获取下一章节ID接口")
@GetMapping("next_chapter_id/{chapterId}")
public RestResp<Long> getNextChapterId(@PathVariable("chapterId") Long chapterId) {
public RestResp<Long> getNextChapterId(@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getNextChapterId(chapterId);
}
/**
* 小说点击榜查询接口
*/
@Operation(description = "小说点击榜查询接口")
@GetMapping("visit_rank")
public RestResp<List<BookRankRespDto>> listVisitRankBooks() {
return bookService.listVisitRankBooks();
@ -106,6 +120,7 @@ public class BookController {
/**
* 小说新书榜查询接口
*/
@Operation(description = "小说新书榜查询接口")
@GetMapping("newest_rank")
public RestResp<List<BookRankRespDto>> listNewestRankBooks() {
return bookService.listNewestRankBooks();
@ -114,6 +129,7 @@ public class BookController {
/**
* 小说更新榜查询接口
*/
@Operation(description = "小说更新榜查询接口")
@GetMapping("update_rank")
public RestResp<List<BookRankRespDto>> listUpdateRankBooks() {
return bookService.listUpdateRankBooks();
@ -122,8 +138,9 @@ public class BookController {
/**
* 小说最新评论查询接口
*/
@Operation(description = "小说最新评论查询接口")
@GetMapping("comment/newest_list")
public RestResp<BookCommentRespDto> listNewestComments(Long bookId) {
public RestResp<BookCommentRespDto> listNewestComments(@Parameter(description = "小说ID") Long bookId) {
return bookService.listNewestComments(bookId);
}

View File

@ -5,6 +5,8 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.dto.resp.HomeBookRespDto;
import io.github.xxyopen.novel.dto.resp.HomeFriendLinkRespDto;
import io.github.xxyopen.novel.service.HomeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -18,6 +20,7 @@ import java.util.List;
* @author xiongxiaoyang
* @date 2022/5/12
*/
@Tag(name = "home", description = "前台门户-首页模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_HOME_URL_PREFIX)
@RequiredArgsConstructor
@ -28,6 +31,7 @@ public class HomeController {
/**
* 首页小说推荐查询接口
*/
@Operation(description = "首页小说推荐查询接口")
@GetMapping("books")
public RestResp<List<HomeBookRespDto>> listHomeBooks() {
return homeService.listHomeBooks();
@ -36,6 +40,7 @@ public class HomeController {
/**
* 首页友情链接列表查询接口
*/
@Operation(description = "首页友情链接列表查询接口")
@GetMapping("friend_Link/list")
public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
return homeService.listHomeFriendLinks();

View File

@ -4,6 +4,9 @@ import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
import io.github.xxyopen.novel.service.NewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -18,6 +21,7 @@ import java.util.List;
* @author xiongxiaoyang
* @date 2022/5/12
*/
@Tag(name = "news", description = "前台门户-新闻模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_NEWS_URL_PREFIX)
@RequiredArgsConstructor
@ -28,6 +32,7 @@ public class NewsController {
/**
* 最新新闻列表查询接口
*/
@Operation(description = "最新新闻列表查询接口")
@GetMapping("latest_list")
public RestResp<List<NewsInfoRespDto>> listLatestNews() {
return newsService.listLatestNews();
@ -36,8 +41,9 @@ public class NewsController {
/**
* 新闻信息查询接口
*/
@Operation(description = "新闻信息查询接口")
@GetMapping("{id}")
public RestResp<NewsInfoRespDto> getNews(@PathVariable Long id) {
public RestResp<NewsInfoRespDto> getNews(@Parameter(description = "新闻ID") @PathVariable Long id) {
return newsService.getNews(id);
}
}

View File

@ -4,6 +4,9 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.resp.ImgVerifyCodeRespDto;
import io.github.xxyopen.novel.service.ResourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -16,6 +19,7 @@ import java.io.IOException;
* @author xiongxiaoyang
* @date 2022/5/17
*/
@Tag(name = "resource", description = "前台门户-资源模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_RESOURCE_URL_PREFIX)
@RequiredArgsConstructor
@ -26,6 +30,7 @@ public class ResourceController {
/**
* 获取图片验证码接口
*/
@Operation(description = "获取图片验证码接口")
@GetMapping("img_verify_code")
public RestResp<ImgVerifyCodeRespDto> getImgVerifyCode() throws IOException {
return resourceService.getImgVerifyCode();
@ -34,8 +39,9 @@ public class ResourceController {
/**
* 图片上传接口
* */
@Operation(description = "图片上传接口")
@PostMapping("/image")
RestResp<String> uploadImage(@RequestParam("file") MultipartFile file) {
RestResp<String> uploadImage(@Parameter(description = "上传文件") @RequestParam("file") MultipartFile file) {
return resourceService.uploadImage(file);
}

View File

@ -6,7 +6,10 @@ import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.SearchService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -17,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author xiongxiaoyang
* @date 2022/5/27
*/
@Tag(name = "search", description = "前台门户-搜索模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_SEARCH_URL_PREFIX)
@RequiredArgsConstructor
@ -27,8 +31,9 @@ public class SearchController {
/**
* 小说搜索接口
*/
@Operation(description = "小说搜索接口")
@GetMapping("books")
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(BookSearchReqDto condition) {
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(@ParameterObject BookSearchReqDto condition) {
return searchService.searchBooks(condition);
}

View File

@ -3,6 +3,7 @@ package io.github.xxyopen.novel.controller.front;
import io.github.xxyopen.novel.core.auth.UserHolder;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
import io.github.xxyopen.novel.dto.req.UserInfoUptReqDto;
import io.github.xxyopen.novel.dto.req.UserLoginReqDto;
@ -12,6 +13,10 @@ import io.github.xxyopen.novel.dto.resp.UserLoginRespDto;
import io.github.xxyopen.novel.dto.resp.UserRegisterRespDto;
import io.github.xxyopen.novel.service.BookService;
import io.github.xxyopen.novel.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@ -22,6 +27,8 @@ import org.springframework.web.bind.annotation.*;
* @author xiongxiaoyang
* @date 2022/5/17
*/
@Tag(name = "user", description = "前台门户-会员模块")
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_USER_URL_PREFIX)
@RequiredArgsConstructor
@ -34,6 +41,7 @@ public class UserController {
/**
* 用户注册接口
*/
@Operation(description = "用户注册接口")
@PostMapping("register")
public RestResp<UserRegisterRespDto> register(@Valid @RequestBody UserRegisterReqDto dto) {
return userService.register(dto);
@ -42,6 +50,7 @@ public class UserController {
/**
* 用户登录接口
*/
@Operation(description = "用户登录接口")
@PostMapping("login")
public RestResp<UserLoginRespDto> login(@Valid @RequestBody UserLoginReqDto dto) {
return userService.login(dto);
@ -50,6 +59,7 @@ public class UserController {
/**
* 用户信息查询接口
*/
@Operation(description = "用户信息查询接口")
@GetMapping
public RestResp<UserInfoRespDto> getUserInfo() {
return userService.getUserInfo(UserHolder.getUserId());
@ -58,6 +68,7 @@ public class UserController {
/**
* 用户信息修改接口
*/
@Operation(description = "用户信息修改接口")
@PutMapping
public RestResp<Void> updateUserInfo(@Valid @RequestBody UserInfoUptReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -67,6 +78,7 @@ public class UserController {
/**
* 用户反馈提交接口
*/
@Operation(description = "用户反馈提交接口")
@PostMapping("feedback")
public RestResp<Void> submitFeedback(@RequestBody String content) {
return userService.saveFeedback(UserHolder.getUserId(), content);
@ -75,14 +87,16 @@ public class UserController {
/**
* 用户反馈删除接口
*/
@Operation(description = "用户反馈删除接口")
@DeleteMapping("feedback/{id}")
public RestResp<Void> deleteFeedback(@PathVariable Long id) {
public RestResp<Void> deleteFeedback(@Parameter(description = "反馈ID") @PathVariable Long id) {
return userService.deleteFeedback(UserHolder.getUserId(), id);
}
/**
* 发表评论接口
*/
@Operation(description = "发表评论接口")
@PostMapping("comment")
public RestResp<Void> comment(@Valid @RequestBody UserCommentReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -92,16 +106,18 @@ public class UserController {
/**
* 修改评论接口
*/
@Operation(description = "修改评论接口")
@PutMapping("comment/{id}")
public RestResp<Void> updateComment(@PathVariable Long id, String content) {
public RestResp<Void> updateComment(@Parameter(description = "评论ID") @PathVariable Long id, String content) {
return bookService.updateComment(UserHolder.getUserId(), id, content);
}
/**
* 删除评论接口
*/
@Operation(description = "删除评论接口")
@DeleteMapping("comment/{id}")
public RestResp<Void> deleteComment(@PathVariable Long id) {
public RestResp<Void> deleteComment(@Parameter(description = "评论ID") @PathVariable Long id) {
return bookService.deleteComment(UserHolder.getUserId(), id);
}
@ -110,8 +126,9 @@ public class UserController {
* 0-不在书架
* 1-已在书架
*/
@Operation(description = "查询书架状态接口")
@GetMapping("bookshelf_status")
public RestResp<Integer> getBookshelfStatus(@RequestBody String bookId) {
public RestResp<Integer> getBookshelfStatus(@Parameter(description = "小说ID") String bookId) {
return userService.getBookshelfStatus(UserHolder.getUserId(), bookId);
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.core.common.req;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.Data;
/**
@ -14,17 +15,20 @@ public class PageReqDto {
/**
* 请求页码默认第 1
* */
@Parameter(description = "请求页码,默认第 1 页")
private int pageNum = 1;
/**
* 每页大小默认每页 10
* */
@Parameter(description = "每页大小,默认每页 10 条")
private int pageSize = 10;
/**
* 是否查询所有默认不查所有
* true pageNum pageSize 无效
* */
@Parameter(hidden = true)
private boolean fetchAll = false;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.core.common.resp;
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import java.util.Objects;
@ -17,16 +18,19 @@ public class RestResp<T> {
/**
* 响应码
*/
@Schema(description = "错误码00000-没有错误")
private String code;
/**
* 响应消息
*/
@Schema(description = "响应消息")
private String message;
/**
* 响应数据
*/
@Schema(description = "响应数据")
private T data;
private RestResp() {

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
@ -17,33 +18,38 @@ public class AuthorRegisterReqDto {
/**
* 笔名
*/
@NotBlank(message="笔名不能为空!")
@Schema(description = "笔名", required = true)
@NotBlank(message = "笔名不能为空!")
private String penName;
/**
* 手机号码
*/
@NotBlank(message="手机号不能为空!")
@Pattern(regexp="^1[3|4|5|6|7|8|9][0-9]{9}$",message="手机号格式不正确!")
@Schema(description = "手机号码", required = true)
@NotBlank(message = "手机号不能为空!")
@Pattern(regexp = "^1[3|4|5|6|7|8|9][0-9]{9}$", message = "手机号格式不正确!")
private String telPhone;
/**
* QQ或微信账号
*/
@NotBlank(message="QQ或微信账号不能为空")
@Schema(description = "QQ或微信账号", required = true)
@NotBlank(message = "QQ或微信账号不能为空")
private String chatAccount;
/**
* 电子邮箱
*/
@NotBlank(message="电子邮箱不能为空!")
@Email(message="邮箱格式不正确!")
@Schema(description = "电子邮箱", required = true)
@NotBlank(message = "电子邮箱不能为空!")
@Email(message = "邮箱格式不正确!")
private String email;
/**
* 作品方向;0-男频 1-女频
*/
@NotNull(message="作品方向不能为空!")
@Schema(description = "作品方向;0-男频 1-女频", required = true)
@NotNull(message = "作品方向不能为空!")
@Min(0)
@Max(1)
private Integer workDirection;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -16,42 +17,49 @@ public class BookAddReqDto {
/**
* 作品方向;0-男频 1-女频
*/
@Schema(description = "作品方向;0-男频 1-女频", required = true)
@NotNull
private Integer workDirection;
/**
* 类别ID
*/
@Schema(description = "类别ID", required = true)
@NotNull
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名", required = true)
@NotBlank
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址", required = true)
@NotBlank
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名", required = true)
@NotBlank
private String bookName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述", required = true)
@NotBlank
private String bookDesc;
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费", required = true)
@NotNull
private Integer isVip;
}

View File

@ -2,6 +2,7 @@ package io.github.xxyopen.novel.dto.req;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.xxyopen.novel.core.common.req.PageReqDto;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -19,36 +20,43 @@ public class BookSearchReqDto extends PageReqDto {
/**
* 搜索关键字
*/
@Parameter(description = "搜索关键字")
private String keyword;
/**
* 作品方向
*/
@Parameter(description = "作品方向")
private Integer workDirection;
/**
* 分类ID
*/
@Parameter(description = "分类ID")
private Integer categoryId;
/**
* 是否收费1收费0免费
*/
@Parameter(description = "是否收费1收费0免费")
private Integer isVip;
/**
* 小说更新状态0连载中1已完结
*/
@Parameter(description = "小说更新状态0连载中1已完结")
private Integer bookStatus;
/**
* 字数最小值
*/
@Parameter(description = "字数最小值")
private Integer wordCountMin;
/**
* 字数最大值
*/
@Parameter(description = "字数最大值")
private Integer wordCountMax;
/**
@ -57,6 +65,7 @@ public class BookSearchReqDto extends PageReqDto {
* 如果使用Post请求@RequestBody接收请求体参数默认解析日期格式为yyyy-MM-dd HH:mm:ss ,
* 如果需要接收其他格式的参数则可以使用@JsonFormat注解
* */
@Parameter(description = "最小更新时间")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateTimeMin;
@ -64,5 +73,6 @@ public class BookSearchReqDto extends PageReqDto {
/**
* 排序字段
*/
@Parameter(description = "排序字段")
private String sort;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -17,17 +18,20 @@ public class ChapterAddReqDto {
/**
* 小说ID
*/
@Schema(description = "小说ID", required = true)
private Long bookId;
/**
* 章节名
*/
@NotBlank
@Schema(description = "章节名", required = true)
private String chapterName;
/**
* 章节内容
*/
@Schema(description = "章节内容", required = true)
@NotBlank
@Length(min = 50)
private String chapterContent;
@ -35,6 +39,7 @@ public class ChapterAddReqDto {
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费", required = true)
@NotNull
private Integer isVip;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -15,9 +16,11 @@ public class UserCommentReqDto {
private Long userId;
@Schema(description = "小说ID", required = true)
@NotNull(message="小说ID不能为空")
private Long bookId;
@Schema(description = "评论内容", required = true)
@NotBlank(message="评论不能为空!")
@Length(min = 10,max = 512)
private String commentContent;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Pattern;
@ -16,12 +17,15 @@ public class UserInfoUptReqDto {
private Long userId;
@Schema(description = "昵称")
@Length(min = 2,max = 10)
private String nickName;
@Schema(description = "头像地址")
@Pattern(regexp="^/[^\s]{10,}\\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF|bpm|BPM)$")
private String userPhoto;
@Schema(description = "性别")
@Min(value = 0)
@Max(value = 1)
private Integer userSex;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
@ -13,10 +14,12 @@ import lombok.Data;
@Data
public class UserLoginReqDto {
@Schema(description = "手机号", required = true)
@NotBlank(message="手机号不能为空!")
@Pattern(regexp="^1[3|4|5|6|7|8|9][0-9]{9}$",message="手机号格式不正确!")
private String username;
@Schema(description = "密码", required = true)
@NotBlank(message="密码不能为空!")
private String password;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
@ -14,13 +15,16 @@ import org.hibernate.validator.constraints.Length;
@Data
public class UserRegisterReqDto {
@Schema(description = "手机号", required = true)
@NotBlank(message="手机号不能为空!")
@Pattern(regexp="^1[3|4|5|6|7|8|9][0-9]{9}$",message="手机号格式不正确!")
private String username;
@Schema(description = "密码", required = true)
@NotBlank(message="密码不能为空!")
private String password;
@Schema(description = "验证码", required = true)
@NotBlank(message="验证码不能为空!")
@Pattern(regexp="^\\d{4}$",message="验证码格式不正确!")
private String velCode;
@ -28,6 +32,7 @@ public class UserRegisterReqDto {
/**
* 请求会话标识用来标识图形验证码属于哪个会话
* */
@Schema(description = "sessionId", required = true)
@NotBlank
@Length(min = 32,max = 32)
private String sessionId;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,11 +17,13 @@ public class BookCategoryRespDto {
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long id;
/**
* 类别名
*/
@Schema(description = "类别名")
private String name;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -18,11 +19,13 @@ public class BookChapterAboutRespDto {
/**
* 章节总数
*/
@Schema(description = "章节总数")
private Long chapterTotal;
/**
* 内容概要30字
*/
@Schema(description = " 内容概要30字")
private String contentSummary;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -24,37 +25,44 @@ public class BookChapterRespDto implements Serializable {
/**
* 章节ID
* */
@Schema(description = "章节ID")
private Long id;
/**
* 小说ID
*/
@Schema(description = "小说ID")
private Long bookId;
/**
* 章节号
*/
@Schema(description = "章节号")
private Integer chapterNum;
/**
* 章节名
*/
@Schema(description = "章节名")
private String chapterName;
/**
* 章节字数
*/
@Schema(description = "章节字数")
private Integer chapterWordCount;
/**
* 章节更新时间
*/
@Schema(description = "章节更新时间")
@JsonFormat(pattern = "yyyy/MM/dd HH:dd")
private LocalDateTime chapterUpdateTime;
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费")
private Integer isVip;
}

View File

@ -3,6 +3,7 @@ package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.github.xxyopen.novel.core.json.serializer.UsernameSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -18,25 +19,33 @@ import java.util.List;
@Builder
public class BookCommentRespDto {
@Schema(description = "评论总数")
private Long commentTotal;
@Schema(description = "评论列表")
private List<CommentInfo> comments;
@Data
@Builder
public static class CommentInfo {
@Schema(description = "评论ID")
private Long id;
@Schema(description = "评论内容")
private String commentContent;
@Schema(description = "评论用户")
@JsonSerialize(using = UsernameSerializer.class)
private String commentUser;
@Schema(description = "评论用户ID")
private Long commentUserId;
@Schema(description = "评论用户头像")
private String commentUserPhoto;
@Schema(description = "评论时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime commentTime;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,16 +17,19 @@ public class BookContentAboutRespDto {
/**
* 小说信息
*/
@Schema(description = "小说信息")
private BookInfoRespDto bookInfo;
/**
* 章节信息
*/
@Schema(description = "章节信息")
private BookChapterRespDto chapterInfo;
/**
* 章节内容
*/
@Schema(description = "章节内容")
private String bookContent;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@ -20,81 +21,97 @@ public class BookInfoRespDto {
/**
* ID
*/
@Schema(description = "小说ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家id
*/
@Schema(description = "作家id")
private Long authorId;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
/**
* 书籍状态;0-连载中 1-已完结
*/
@Schema(description = "书籍状态;0-连载中 1-已完结")
private Integer bookStatus;
/**
* 点击量
*/
@Schema(description = "点击量")
private Long visitCount;
/**
* 总字数
*/
@Schema(description = "总字数")
private Integer wordCount;
/**
* 评论数
*/
@Schema(description = "评论数")
private Integer commentCount;
/**
* 首章节ID
*/
@Schema(description = "首章节ID")
private Long firstChapterId;
/**
* 最新章节ID
*/
@Schema(description = "最新章节ID")
private Long lastChapterId;
/**
* 最新章节名
*/
@Schema(description = "最新章节名")
private String lastChapterName;
/**
* 最新章节更新时间
*/
@Schema(description = "最新章节更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime updateTime;

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
@ -22,51 +23,61 @@ public class BookRankRespDto implements Serializable {
/**
* ID
*/
@Schema(description = "小说ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
/**
* 总字数
*/
@Schema(description = "总字数")
private Integer wordCount;
/**
* 最新章节名
*/
@Schema(description = "最新章节名")
private String lastChapterName;
/**
* 最新章节更新时间
*/
@Schema(description = "最新章节更新时间")
@JsonFormat(pattern = "MM/dd HH:mm")
private LocalDateTime lastChapterUpdateTime;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
@ -14,31 +15,37 @@ public class HomeBookRespDto {
/**
* 类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐
*/
@Schema(description = "类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐")
private Integer type;
/**
* 推荐小说ID
*/
@Schema(description = "小说ID")
private Long bookId;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
@ -20,10 +21,12 @@ public class HomeFriendLinkRespDto implements Serializable {
/**
* 链接名
*/
@Schema(description = "链接名")
private String linkName;
/**
* 链接url
*/
@Schema(description = "链接url")
private String linkUrl;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -15,11 +16,13 @@ public class ImgVerifyCodeRespDto {
/**
* 当前会话ID用于标识改图形验证码属于哪个会话
* */
@Schema(description = "sessionId")
private String sessionId;
/**
* Base64 编码的验证码图片
* */
@Schema(description = "Base64 编码的验证码图片")
private String img;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -19,37 +20,44 @@ public class NewsInfoRespDto {
/**
* ID
*/
@Schema(description = "新闻ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 新闻来源
*/
@Schema(description = "新闻来源")
private String sourceName;
/**
* 新闻标题
*/
@Schema(description = "新闻标题")
private String title;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDateTime updateTime;
/**
* 新闻内容
* */
@Schema(description = "新闻内容")
private String content;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,15 +17,18 @@ public class UserInfoRespDto {
/**
* 昵称
* */
@Schema(description = "昵称")
private String nickName;
/**
* 用户头像
* */
@Schema(description = "用户头像")
private String userPhoto;
/**
* 用户性别
* */
@Schema(description = "用户性别")
private Integer userSex;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -12,9 +13,12 @@ import lombok.Data;
@Builder
public class UserLoginRespDto {
@Schema(description = "用户ID")
private Long uid;
@Schema(description = "用户昵称")
private String nickName;
@Schema(description = "用户token")
private String token;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -12,7 +13,9 @@ import lombok.Data;
@Builder
public class UserRegisterRespDto {
@Schema(description = "用户ID")
private Long uid;
@Schema(description = "用户token")
private String token;
}