Skip to content

Commit

Permalink
fix: NOTICE board readable by non-login
Browse files Browse the repository at this point in the history
  • Loading branch information
becooq81 committed Aug 28, 2024
1 parent 3b441fc commit 14db107
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ResponseEntity<Void> registerPost(@AuthenticationPrincipal Member member,
@GetMapping("/post/{postId}")
public ResponseEntity<PostResponse> 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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/poolc/api/post/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<Post> posts = postRepository.findByBoardType(boardType, pr);
if (posts.getNumberOfElements() == 0) return null;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/poolc/api/scrap/service/ScrapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 14db107

Please sign in to comment.