Commit 87da0782 authored by 刘基明's avatar 刘基明

删除主题评论

parent 9b9d7302
......@@ -71,4 +71,14 @@ public class CommentController {
commentManager.report(req,userId);
return CommonResp.success();
}
@ApiOperation("删除评论")
@GetMapping(value = "/deleteComment")
@AuthLogin
@ResponseBody
public CommonResp<Void> reportComment(@RequestParam(value = "commentId") String commentId) {
String userId = userHolder.getUserId();
commentManager.delete(commentId,userId);
return CommonResp.success();
}
}
......@@ -124,4 +124,10 @@ public class CommentManager {
CommentEntity commentEntity = commentService.queryByCommentId(req.getCommentId());
reportLogService.insert(ReportTypeEnum.COMMENT, userId, req.getCommentId(), commentEntity.getAuthorId(), req.getReason());
}
//删除评论
public void delete(String commentId, String userId) {
commentService.delete(commentId,userId);
}
}
......@@ -415,9 +415,9 @@ public class ThemeManager {
}
//逻辑删除主题 TODO
// 逻辑删除主题,校验用户
public void delete(String themeId,String userId) {
themeService.deleteById(themeId);
themeService.deleteById(themeId,userId);
}
......
......@@ -124,4 +124,18 @@ public class CommentService {
commentMapper.updateById(commentEntity);
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentId));
}
//删除评论
@Transactional
public void delete(String commentId, String userId) {
CommentEntity commentEntity = this.queryByCommentId(commentId);
if (commentEntity==null || !commentEntity.getAuthorId().equals(userId)){
throw new BizException("删除评论与用户不匹配,commentId:"+commentId+",userId:"+userId);
}
commentEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
commentMapper.updateById(commentEntity);
//删除主题的评论列表缓存
redisCache.evict(StringUtils.joinWith("_", CAHCE_COMMENT_ID, commentEntity.getThemeId()));
}
}
......@@ -263,11 +263,11 @@ public class ThemeService {
}
@Transactional
public void deleteById(String themeId) {
public void deleteById(String themeId,String userId) {
ThemeEntity themeEntity = themeMapper.selectOne(new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getThemeId, themeId));
if (themeEntity == null) {
throw new BizException("主题未找到,id:" + themeId);
if (themeEntity == null || !themeEntity.getAuthorId().equals(userId)) {
throw new BizException("主题与用户不匹配,id:" + themeId+",userId"+userId);
}
themeEntity.setDeleteTag(DeleteTagEnum.DELETED.getCode());
themeMapper.updateById(themeEntity);
......
......@@ -8,7 +8,7 @@ apollo.bootstrap.enabled: true
# namespaces: application.yml
server:
port: 8060
port: 8080
servlet:
context-path: /community
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment