提交 54a7da25 authored 作者: Whispa's avatar Whispa

commit commit

上级 e81c2be4
......@@ -28,25 +28,29 @@ public class ItemLikeController {
@PutMapping("like/{comment_id}")
public Result likeComment(@PathVariable("comment_id") String commentId ){
Optional<TbCfItemComment> commentOptional = commentRepository.findById(commentId);
try {
Optional<TbCfItemComment> commentOptional = commentRepository.findById(commentId);
if( !commentOptional.isPresent() )
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(),"Item comment not found !");
TbCfUserInfo user = this.user.user();
String userId = user.getUserId();
boolean exists = repository.existsByCommentIdAndUserUserId(commentId, userId);
if( !commentOptional.isPresent() )
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(),"Item comment not found !");
TbCfUserInfo user = this.user.user();
String userId = user.getUserId();
boolean exists = repository.existsByCommentIdAndUserUserId(commentId, userId);
if( exists ){
repository.deleteAllByCommentIdAndUserUserId(commentId,userId);
return new Result<>(false,"Comment disliked");
}
if( exists ){
repository.deleteAllByCommentIdAndUserUserId(commentId,userId);
return new Result<>(false,"Comment disliked");
}
TbCfItemLike itemLike = new TbCfItemLike();
TbCfItemLike itemLike = new TbCfItemLike();
itemLike.setUser(user);
itemLike.setComment(commentOptional.get());
itemLike.setUser(user);
itemLike.setComment(commentOptional.get());
repository.save(itemLike);
repository.save(itemLike);
}catch (Exception e){
System.out.println(e.getMessage());
}
return new Result<>(true,"Comment liked");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论