diff --git a/src/main/java/org/poolc/api/post/controller/PostController.java b/src/main/java/org/poolc/api/post/controller/PostController.java index 2c3d7d3f..0848c86e 100644 --- a/src/main/java/org/poolc/api/post/controller/PostController.java +++ b/src/main/java/org/poolc/api/post/controller/PostController.java @@ -40,7 +40,7 @@ public ResponseEntity registerPost(@AuthenticationPrincipal Member member, @GetMapping("/post/{postId}") public ResponseEntity viewPost(@AuthenticationPrincipal Member member, @PathVariable Long postId) { Post post = postService.findById(member, postId); - PostResponse response = PostResponse.of(post, scrapService.isScrap(member.getLoginID(),postId)); + PostResponse response = PostResponse.of(post, scrapService.isScrap(member, postId)); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/src/main/java/org/poolc/api/post/service/PostService.java b/src/main/java/org/poolc/api/post/service/PostService.java index 7522d4f4..adb33469 100644 --- a/src/main/java/org/poolc/api/post/service/PostService.java +++ b/src/main/java/org/poolc/api/post/service/PostService.java @@ -35,7 +35,7 @@ public class PostService { public Post findById(Member member, Long postId) { Post post = postRepository.findById(postId) .orElseThrow(() -> new NoSuchElementException("No post found with given post id.")); - checkReadPermission(member, post.getBoardType()); + if (post.getBoardType() != BoardType.NOTICE) checkReadPermission(member, post.getBoardType()); post.getCommentList().sort(Comparator.comparing(Comment::getCreatedAt)); return post; } @@ -55,7 +55,7 @@ public GetBoardResponse findPostsByMember(Member member, int page) { @Transactional(readOnly = true) public GetBoardResponse findPostsByBoard(Member member, BoardType boardType, int page) { - checkReadPermission(member, boardType); + if (BoardType.NOTICE != boardType) checkReadPermission(member, boardType); PageRequest pr = PageRequest.of(page, size, Sort.by("createdAt").descending()); Page posts = postRepository.findByBoardType(boardType, pr); if (posts.getNumberOfElements() == 0) return null; diff --git a/src/main/java/org/poolc/api/scrap/service/ScrapService.java b/src/main/java/org/poolc/api/scrap/service/ScrapService.java index 93270a30..a42b0450 100644 --- a/src/main/java/org/poolc/api/scrap/service/ScrapService.java +++ b/src/main/java/org/poolc/api/scrap/service/ScrapService.java @@ -35,8 +35,9 @@ public void scrap(String memberId, Long postId) { } } - public boolean isScrap(String memberId, Long postId){ - if(scrapRepository.existsByMemberIdAndPostId(memberId, postId)) { + public boolean isScrap(Member member, Long postId){ + if (member == null) return false; + if(scrapRepository.existsByMemberIdAndPostId(member.getLoginID(), postId)) { return true; } return false;