mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
fix: 章节发布校验
This commit is contained in:
parent
ad907063d9
commit
785646b4c4
@ -42,7 +42,7 @@ public class AuthorController {
|
||||
|
||||
/**
|
||||
* 查询作家状态接口
|
||||
* */
|
||||
*/
|
||||
@GetMapping("status")
|
||||
public RestResp<Integer> getStatus() {
|
||||
return authorService.getStatus(UserHolder.getUserId());
|
||||
@ -67,8 +67,9 @@ public class AuthorController {
|
||||
/**
|
||||
* 小说章节发布接口
|
||||
*/
|
||||
@PostMapping("book/chapter")
|
||||
public RestResp<Void> publishBookChapter(@Valid @RequestBody ChapterAddReqDto dto) {
|
||||
@PostMapping("book/chapter/{bookId}")
|
||||
public RestResp<Void> publishBookChapter(@PathVariable("bookId") Long bookId, @Valid @RequestBody ChapterAddReqDto dto) {
|
||||
dto.setBookId(bookId);
|
||||
return bookService.saveBookChapter(dto);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ public class ChapterAddReqDto {
|
||||
/**
|
||||
* 小说ID
|
||||
*/
|
||||
@NotNull
|
||||
private Long bookId;
|
||||
|
||||
/**
|
||||
|
@ -300,6 +300,11 @@ public class BookServiceImpl implements BookService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public RestResp<Void> saveBookChapter(ChapterAddReqDto dto) {
|
||||
// 校验该作品是否属于当前作家
|
||||
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(dto.getBookId());
|
||||
if (!Objects.equals(bookInfo.getAuthorId(), UserHolder.getAuthorId())) {
|
||||
return RestResp.fail(ErrorCodeEnum.USER_UN_AUTH);
|
||||
}
|
||||
// 1) 保存章节相关信息到小说章节表
|
||||
// a) 查询最新章节号
|
||||
int chapterNum = 0;
|
||||
@ -332,7 +337,6 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
// 3) 更新小说表最新章节信息和小说总字数信息
|
||||
// a) 更新小说表关于最新章节的信息
|
||||
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(dto.getBookId());
|
||||
BookInfo newBookInfo = new BookInfo();
|
||||
newBookInfo.setId(dto.getBookId());
|
||||
newBookInfo.setLastChapterId(newBookChapter.getId());
|
||||
|
Loading…
x
Reference in New Issue
Block a user