mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
feat: 增加评论修改接口
This commit is contained in:
parent
f163c77cf6
commit
07636a4252
@ -26,7 +26,6 @@ public class ResourceController {
|
||||
|
||||
/**
|
||||
* 获取图片验证码接口
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("img_verify_code")
|
||||
public RestResp<ImgVerifyCodeRespDto> getImgVerifyCode() throws IOException {
|
||||
|
@ -8,6 +8,7 @@ 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.dto.resp.UserRegisterRespDto;
|
||||
import io.github.xxyopen.novel.service.BookService;
|
||||
import io.github.xxyopen.novel.service.UserService;
|
||||
import jakarta.validation.Valid;
|
||||
@ -33,7 +34,7 @@ public class UserController {
|
||||
* 用户注册接口
|
||||
*/
|
||||
@PostMapping("register")
|
||||
public RestResp<String> register(@Valid @RequestBody UserRegisterReqDto dto) {
|
||||
public RestResp<UserRegisterRespDto> register(@Valid @RequestBody UserRegisterReqDto dto) {
|
||||
return userService.register(dto);
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* 用户反馈删除接口
|
||||
* */
|
||||
*/
|
||||
@DeleteMapping("feedback/{id}")
|
||||
public RestResp<Void> deleteFeedback(@PathVariable Long id) {
|
||||
return userService.deleteFeedback(UserHolder.getUserId(), id);
|
||||
@ -73,16 +74,24 @@ public class UserController {
|
||||
|
||||
/**
|
||||
* 发表评论接口
|
||||
* */
|
||||
*/
|
||||
@PostMapping("comment")
|
||||
public RestResp<Void> comment(@Valid @RequestBody UserCommentReqDto dto) {
|
||||
dto.setUserId(UserHolder.getUserId());
|
||||
return bookService.saveComment(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改评论接口
|
||||
*/
|
||||
@PutMapping("comment/{id}")
|
||||
public RestResp<Void> updateComment(@PathVariable Long id, String content) {
|
||||
return bookService.updateComment(UserHolder.getUserId(), id, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评论接口
|
||||
* */
|
||||
*/
|
||||
@DeleteMapping("comment/{id}")
|
||||
public RestResp<Void> deleteComment(@PathVariable Long id) {
|
||||
return bookService.deleteComment(UserHolder.getUserId(), id);
|
||||
@ -92,7 +101,7 @@ public class UserController {
|
||||
* 查询书架状态接口
|
||||
* 0-不在书架
|
||||
* 1-已在书架
|
||||
* */
|
||||
*/
|
||||
@GetMapping("bookshelf_status")
|
||||
public RestResp<Integer> getBookshelfStatus(@RequestBody String bookId) {
|
||||
return userService.getBookshelfStatus(UserHolder.getUserId(), bookId);
|
||||
|
@ -34,6 +34,8 @@ public class BookCommentRespDto {
|
||||
@JsonSerialize(using = UsernameSerializer.class)
|
||||
private String commentUser;
|
||||
|
||||
private Long commentUserId;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime commentTime;
|
||||
|
||||
|
@ -12,6 +12,8 @@ import lombok.Data;
|
||||
@Builder
|
||||
public class UserLoginRespDto {
|
||||
|
||||
private Long uid;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String token;
|
||||
|
@ -0,0 +1,18 @@
|
||||
package io.github.xxyopen.novel.dto.resp;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户注册 响应DTO
|
||||
* @author xiongxiaoyang
|
||||
* @date 2022/5/17
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class UserRegisterRespDto {
|
||||
|
||||
private Long uid;
|
||||
|
||||
private String token;
|
||||
}
|
@ -141,4 +141,13 @@ public interface BookService {
|
||||
* @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);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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.dto.resp.UserRegisterRespDto;
|
||||
|
||||
/**
|
||||
* 会员模块 服务类
|
||||
@ -20,7 +21,7 @@ public interface UserService {
|
||||
* @param dto 注册参数
|
||||
* @return JWT
|
||||
*/
|
||||
RestResp<String> register(UserRegisterReqDto dto);
|
||||
RestResp<UserRegisterRespDto> register(UserRegisterReqDto dto);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
|
@ -248,6 +248,7 @@ public class BookServiceImpl implements BookService {
|
||||
List<BookCommentRespDto.CommentInfo> commentInfos = bookComments.stream()
|
||||
.map(v -> BookCommentRespDto.CommentInfo.builder()
|
||||
.id(v.getId())
|
||||
.commentUserId(v.getUserId())
|
||||
.commentUser(userInfoMap.get(v.getUserId()))
|
||||
.commentContent(v.getCommentContent())
|
||||
.commentTime(v.getCreateTime()).build()).toList();
|
||||
@ -267,6 +268,17 @@ public class BookServiceImpl implements BookService {
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<Void> updateComment(Long userId, Long id, String content) {
|
||||
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), id)
|
||||
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,userId);
|
||||
BookComment bookComment = new BookComment();
|
||||
bookComment.setCommentContent(content);
|
||||
bookCommentMapper.update(bookComment,queryWrapper);
|
||||
return RestResp.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
|
||||
// 查询章节信息
|
||||
|
@ -18,6 +18,7 @@ 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.dto.resp.UserRegisterRespDto;
|
||||
import io.github.xxyopen.novel.manager.VerifyCodeManager;
|
||||
import io.github.xxyopen.novel.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -49,7 +50,7 @@ public class UserServiceImpl implements UserService {
|
||||
private final JwtUtils jwtUtils;
|
||||
|
||||
@Override
|
||||
public RestResp<String> register(UserRegisterReqDto dto) {
|
||||
public RestResp<UserRegisterRespDto> register(UserRegisterReqDto dto) {
|
||||
// 校验图形验证码是否正确
|
||||
if (!verifyCodeManager.imgVerifyCodeOk(dto.getSessionId(), dto.getVelCode())) {
|
||||
// 图形验证码校验失败
|
||||
@ -79,7 +80,13 @@ public class UserServiceImpl implements UserService {
|
||||
verifyCodeManager.removeImgVerifyCode(dto.getSessionId());
|
||||
|
||||
// 生成JWT 并返回
|
||||
return RestResp.ok(jwtUtils.generateToken(userInfo.getId(), SystemConfigConsts.NOVEL_FRONT_KEY));
|
||||
return RestResp.ok(
|
||||
UserRegisterRespDto.builder()
|
||||
.token(jwtUtils.generateToken(userInfo.getId(), SystemConfigConsts.NOVEL_FRONT_KEY))
|
||||
.uid(userInfo.getId())
|
||||
.build()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,6 +111,7 @@ public class UserServiceImpl implements UserService {
|
||||
// 登录成功,生成JWT并返回
|
||||
return RestResp.ok(UserLoginRespDto.builder()
|
||||
.token(jwtUtils.generateToken(userInfo.getId(), SystemConfigConsts.NOVEL_FRONT_KEY))
|
||||
.uid(userInfo.getId())
|
||||
.nickName(userInfo.getNickName()).build());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user