Skip to content

Commit

Permalink
Merge pull request #2 from Wilcolab/feat/fail
Browse files Browse the repository at this point in the history
chore: fail
  • Loading branch information
darmalovan authored Jan 17, 2024
2 parents 8988ac0 + 4f60302 commit ad8370b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/src/main/java/io/spring/api/CommentsApi.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.spring.api;

import com.fasterxml.jackson.annotation.JsonRootName;
import io.spring.api.exception.NoAuthorizationException;
import io.spring.api.exception.ResourceNotFoundException;
import io.spring.application.CommentQueryService;
import io.spring.application.data.CommentData;
import io.spring.core.comment.Comment;
import io.spring.core.comment.CommentRepository;
import io.spring.core.item.Item;
import io.spring.core.item.ItemRepository;
import io.spring.core.service.AuthorizationService;
import io.spring.core.user.User;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -70,6 +72,9 @@ public ResponseEntity deleteComment(
.findById(item.getId(), commentId)
.map(
comment -> {
if (!AuthorizationService.canWriteComment(user, item, comment)) {
throw new NoAuthorizationException();
}
commentRepository.remove(comment);
return ResponseEntity.noContent().build();
})
Expand Down

0 comments on commit ad8370b

Please sign in to comment.