mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 增加用户评论发表接口
This commit is contained in:
parent
195846bc0f
commit
cb8f347ccc
@ -3,11 +3,12 @@ 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.util.JwtUtils;
|
||||
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.UserInfoUptReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.UserLoginReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.UserRegisterReqDto;
|
||||
import io.github.xxyopen.novel.dto.resp.UserLoginRespDto;
|
||||
import io.github.xxyopen.novel.service.BookService;
|
||||
import io.github.xxyopen.novel.service.UserService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -26,7 +27,7 @@ public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
private final BookService bookService;
|
||||
|
||||
/**
|
||||
* 用户注册接口
|
||||
@ -70,4 +71,13 @@ public class UserController {
|
||||
return userService.deleteFeedback(UserHolder.getUserId(), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发表评论接口
|
||||
* */
|
||||
@PostMapping("comment")
|
||||
public RestResp<Void> comment(@RequestBody UserCommentReqDto dto) {
|
||||
dto.setUserId(UserHolder.getUserId());
|
||||
return bookService.saveComment(dto);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package io.github.xxyopen.novel.dto.req;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
/**
|
||||
* 用户发表评论 请求DTO
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/17
|
||||
*/
|
||||
@Data
|
||||
public class UserCommentReqDto {
|
||||
|
||||
private Long userId;
|
||||
|
||||
@NotBlank(message="小说ID不能为空!")
|
||||
private Long bookId;
|
||||
|
||||
@NotBlank(message="评论不能为空!")
|
||||
@Length(min = 10,max = 512)
|
||||
private String commentContent;
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package io.github.xxyopen.novel.service;
|
||||
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.BookSearchReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
||||
import io.github.xxyopen.novel.dto.resp.*;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -103,4 +104,11 @@ public interface BookService {
|
||||
* @return 分类列表
|
||||
* */
|
||||
RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection);
|
||||
|
||||
/**
|
||||
* 发表评论
|
||||
* @param dto 评论相关 DTO
|
||||
* @return void
|
||||
* */
|
||||
RestResp<Void> saveComment(UserCommentReqDto dto);
|
||||
}
|
||||
|
@ -6,10 +6,13 @@ 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.BookChapter;
|
||||
import io.github.xxyopen.novel.dao.entity.BookComment;
|
||||
import io.github.xxyopen.novel.dao.entity.BookInfo;
|
||||
import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
|
||||
import io.github.xxyopen.novel.dao.mapper.BookCommentMapper;
|
||||
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
|
||||
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
|
||||
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
|
||||
import io.github.xxyopen.novel.dto.resp.*;
|
||||
import io.github.xxyopen.novel.manager.*;
|
||||
import io.github.xxyopen.novel.service.BookService;
|
||||
@ -19,6 +22,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -49,6 +53,8 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
private final BookChapterMapper bookChapterMapper;
|
||||
|
||||
private final BookCommentMapper bookCommentMapper;
|
||||
|
||||
private static final Integer REC_BOOK_COUNT = 4;
|
||||
|
||||
@Override
|
||||
@ -197,6 +203,18 @@ public class BookServiceImpl implements BookService {
|
||||
return RestResp.ok(bookCategoryCacheManager.listCategory(workDirection));
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<Void> saveComment(UserCommentReqDto dto) {
|
||||
BookComment bookComment = new BookComment();
|
||||
bookComment.setBookId(dto.getBookId());
|
||||
bookComment.setUserId(dto.getUserId());
|
||||
bookComment.setCommentContent(dto.getCommentContent());
|
||||
bookComment.setCreateTime(LocalDateTime.now());
|
||||
bookComment.setUpdateTime(LocalDateTime.now());
|
||||
bookCommentMapper.insert(bookComment);
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
||||
// 查询章节信息
|
||||
|
Loading…
x
Reference in New Issue
Block a user