feat: 增加删除评论接口

This commit is contained in:
xiongxiaoyang 2022-05-20 10:43:14 +08:00
parent 85c6d9119d
commit f163c77cf6
4 changed files with 28 additions and 0 deletions

View File

@ -80,6 +80,14 @@ public class UserController {
return bookService.saveComment(dto);
}
/**
* 删除评论接口
* */
@DeleteMapping("comment/{id}")
public RestResp<Void> deleteComment(@PathVariable Long id) {
return bookService.deleteComment(UserHolder.getUserId(),id);
}
/**
* 查询书架状态接口
* 0-不在书架

View File

@ -27,6 +27,8 @@ public class BookCommentRespDto {
@Builder
public static class CommentInfo {
private Long id;
private String commentContent;
@JsonSerialize(using = UsernameSerializer.class)

View File

@ -133,4 +133,12 @@ public interface BookService {
* @return 小说最新评论数据
*/
RestResp<BookCommentRespDto> listNewestComments(Long bookId);
/**
* 删除评论
* @param userId 评论用户ID
* @param commentId 评论ID
* @return void
* */
RestResp<Void> deleteComment(Long userId, Long commentId);
}

View File

@ -247,6 +247,7 @@ public class BookServiceImpl implements BookService {
Map<Long, String> userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, UserInfo::getUsername));
List<BookCommentRespDto.CommentInfo> commentInfos = bookComments.stream()
.map(v -> BookCommentRespDto.CommentInfo.builder()
.id(v.getId())
.commentUser(userInfoMap.get(v.getUserId()))
.commentContent(v.getCommentContent())
.commentTime(v.getCreateTime()).build()).toList();
@ -257,6 +258,15 @@ public class BookServiceImpl implements BookService {
return RestResp.ok(bookCommentRespDto);
}
@Override
public RestResp<Void> deleteComment(Long userId, Long commentId) {
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(DatabaseConsts.CommonColumnEnum.ID.getName(), commentId)
.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID,userId);
bookCommentMapper.delete(queryWrapper);
return RestResp.ok();
}
@Override
public RestResp<BookContentAboutRespDto> getBookContentAbout(Long chapterId) {
// 查询章节信息