mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 增加小说发布接口
This commit is contained in:
parent
879673bca5
commit
45fdb58ab3
@ -4,7 +4,9 @@ import io.github.xxyopen.novel.core.auth.UserHolder;
|
|||||||
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.service.AuthorService;
|
import io.github.xxyopen.novel.service.AuthorService;
|
||||||
|
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.PostMapping;
|
||||||
@ -24,6 +26,8 @@ public class AuthorController {
|
|||||||
|
|
||||||
private final AuthorService authorService;
|
private final AuthorService authorService;
|
||||||
|
|
||||||
|
private final BookService bookService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作家注册接口
|
* 作家注册接口
|
||||||
*/
|
*/
|
||||||
@ -33,4 +37,12 @@ public class AuthorController {
|
|||||||
return authorService.register(dto);
|
return authorService.register(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说发布接口
|
||||||
|
*/
|
||||||
|
@PostMapping("book")
|
||||||
|
public RestResp<Void> publishBook(@Valid @RequestBody BookAddReqDto dto) {
|
||||||
|
return bookService.saveBook(dto);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ public class AuthorInfoDto implements Serializable {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
private String penName;
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package io.github.xxyopen.novel.dto.req;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说发布 请求DTO
|
||||||
|
*
|
||||||
|
* @author xiongxiaoyang
|
||||||
|
* @date 2022/5/23
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BookAddReqDto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 作品方向;0-男频 1-女频
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Integer workDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类别ID
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类别名
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说封面地址
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String picUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说名
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String bookName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 书籍描述
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String bookDesc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否收费;1-收费 0-免费
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
private Integer isVip;
|
||||||
|
}
|
@ -41,6 +41,7 @@ public class AuthorInfoCacheManager {
|
|||||||
}
|
}
|
||||||
return AuthorInfoDto.builder()
|
return AuthorInfoDto.builder()
|
||||||
.id(authorInfo.getId())
|
.id(authorInfo.getId())
|
||||||
|
.penName(authorInfo.getPenName())
|
||||||
.status(authorInfo.getStatus()).build();
|
.status(authorInfo.getStatus()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package io.github.xxyopen.novel.service;
|
|||||||
|
|
||||||
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
|
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.BookSearchReqDto;
|
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
||||||
import io.github.xxyopen.novel.dto.resp.*;
|
import io.github.xxyopen.novel.dto.resp.*;
|
||||||
@ -150,4 +151,11 @@ public interface BookService {
|
|||||||
* @return void
|
* @return void
|
||||||
* */
|
* */
|
||||||
RestResp<Void> updateComment(Long userId, Long id, String content);
|
RestResp<Void> updateComment(Long userId, Long id, String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小说发布
|
||||||
|
* @param dto 小说信息
|
||||||
|
* @return void
|
||||||
|
* */
|
||||||
|
RestResp<Void> saveBook(BookAddReqDto dto);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,17 @@ 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.extension.plugins.pagination.Page;
|
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.constant.ErrorCodeEnum;
|
||||||
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
|
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.BookChapter;
|
import io.github.xxyopen.novel.dao.entity.*;
|
||||||
import io.github.xxyopen.novel.dao.entity.BookComment;
|
|
||||||
import io.github.xxyopen.novel.dao.entity.BookInfo;
|
|
||||||
import io.github.xxyopen.novel.dao.entity.UserInfo;
|
|
||||||
import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
|
import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
|
||||||
import io.github.xxyopen.novel.dao.mapper.BookCommentMapper;
|
import io.github.xxyopen.novel.dao.mapper.BookCommentMapper;
|
||||||
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
|
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
|
||||||
|
import io.github.xxyopen.novel.dto.AuthorInfoDto;
|
||||||
|
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
|
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
|
||||||
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
||||||
import io.github.xxyopen.novel.dto.resp.*;
|
import io.github.xxyopen.novel.dto.resp.*;
|
||||||
@ -50,6 +50,8 @@ public class BookServiceImpl implements BookService {
|
|||||||
|
|
||||||
private final BookContentCacheManager bookContentCacheManager;
|
private final BookContentCacheManager bookContentCacheManager;
|
||||||
|
|
||||||
|
private final AuthorInfoCacheManager authorInfoCacheManager;
|
||||||
|
|
||||||
private final BookInfoMapper bookInfoMapper;
|
private final BookInfoMapper bookInfoMapper;
|
||||||
|
|
||||||
private final BookChapterMapper bookChapterMapper;
|
private final BookChapterMapper bookChapterMapper;
|
||||||
@ -281,6 +283,29 @@ public class BookServiceImpl implements BookService {
|
|||||||
return RestResp.ok();
|
return RestResp.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RestResp<Void> saveBook(BookAddReqDto dto) {
|
||||||
|
BookInfo bookInfo = new BookInfo();
|
||||||
|
// 设置作家信息
|
||||||
|
AuthorInfoDto author = authorInfoCacheManager.getAuthor(UserHolder.getUserId());
|
||||||
|
bookInfo.setAuthorId(author.getId());
|
||||||
|
bookInfo.setAuthorName(author.getPenName());
|
||||||
|
// 设置其他信息
|
||||||
|
bookInfo.setWorkDirection(dto.getWorkDirection());
|
||||||
|
bookInfo.setCategoryId(dto.getCategoryId());
|
||||||
|
bookInfo.setCategoryName(dto.getCategoryName());
|
||||||
|
bookInfo.setBookName(dto.getBookName());
|
||||||
|
bookInfo.setPicUrl(dto.getPicUrl());
|
||||||
|
bookInfo.setBookDesc(dto.getBookDesc());
|
||||||
|
bookInfo.setIsVip(dto.getIsVip());
|
||||||
|
bookInfo.setScore(0);
|
||||||
|
bookInfo.setCreateTime(LocalDateTime.now());
|
||||||
|
bookInfo.setUpdateTime(LocalDateTime.now());
|
||||||
|
// 保存小说信息
|
||||||
|
bookInfoMapper.insert(bookInfo);
|
||||||
|
return RestResp.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
||||||
// 查询章节信息
|
// 查询章节信息
|
||||||
|
Loading…
x
Reference in New Issue
Block a user