Skip to content

Commit

Permalink
[hotfix] #118 권한 필드명 통일 및 게시물의 댓글 존재하지 않을 때도 권한 반환하기 위하여 권한 필드 depth 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
chahyunsoo committed Sep 26, 2024
1 parent 2485014 commit f67d66a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import ussum.homepage.domain.comment.PostComment;
import ussum.homepage.domain.comment.service.PostCommentFormatter;
import ussum.homepage.domain.comment.service.PostCommentReader;
import ussum.homepage.domain.post.Post;
import ussum.homepage.domain.post.service.PostReader;
import ussum.homepage.domain.reaction.service.PostCommentReactionManager;
import ussum.homepage.domain.reaction.service.PostReplyCommentReactionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@

public record CommentListResponse(
List<PostCommentResponse> postComments,
Integer total
Integer total,
List<String> allowedAuthorities
) {
public static CommentListResponse of(List<PostCommentResponse> postCommentResponses, Integer total) {
return new CommentListResponse(postCommentResponses, total);
return new CommentListResponse(postCommentResponses, total, List.of());
}

public void validAuthority(List<String> canAuthorityList) {
postComments.forEach(postComment -> {
postComment.canAuthority(canAuthorityList);
postComment.getPostReplyComments().stream().forEach(
postReplyComment -> postReplyComment.canAuthority(canAuthorityList)
);
});
// public void validAuthority(List<String> canAuthorityList) {
// postComments.forEach(postComment -> {
// postComment.canAuthority(canAuthorityList);
// postComment.getPostReplyComments().stream().forEach(
// postReplyComment -> postReplyComment.canAuthority(canAuthorityList)
// );
// });
// }

public CommentListResponse validAuthorities(List<String> allowedAuthorities) {
return new CommentListResponse(this.postComments, this.total, allowedAuthorities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class PostCommentResponse {
public Boolean isLiked;
public Boolean isDeleted;
public List<PostReplyCommentResponse> postReplyComments;
public List<String> canAuthority;
// public List<String> canAuthority;

@Builder
public PostCommentResponse(Long id, String authorName, String studentId, String content, String commentType, String createdAt, String lastEditedAt, Integer likeCount, Boolean isAuthor, Boolean isLiked, Boolean isDeleted, List<PostReplyCommentResponse> postReplyComments, List<String> canAuthority) {
public PostCommentResponse(Long id, String authorName, String studentId, String content, String commentType, String createdAt, String lastEditedAt, Integer likeCount, Boolean isAuthor, Boolean isLiked, Boolean isDeleted, List<PostReplyCommentResponse> postReplyComments/*, List<String> canAuthority*/) {
this.id = id;
this.authorName = authorName;
this.studentId = studentId;
Expand All @@ -37,7 +37,7 @@ public PostCommentResponse(Long id, String authorName, String studentId, String
this.isLiked = isLiked;
this.isDeleted = isDeleted;
this.postReplyComments = postReplyComments;
this.canAuthority = canAuthority;
// this.canAuthority = canAuthority;
}

public static PostCommentResponse of(PostComment postComment, User user, String commentType, Integer likeCount, Boolean isAuthor, Boolean isLiked, List<PostReplyCommentResponse> postReplyComments) {
Expand All @@ -64,8 +64,8 @@ public static PostCommentResponse of(PostComment postComment, User user, String
.build();
}

public void canAuthority(List<String> canAuthorityList) {
this.canAuthority = canAuthorityList;
}
// public void canAuthority(List<String> canAuthorityList) {
// this.canAuthority = canAuthorityList;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class PostReplyCommentResponse {
public Boolean isAuthor;
public Boolean isLiked;
public Boolean isDeleted;
public List<String> canAuthority;
// public List<String> canAuthority;

@Builder
public PostReplyCommentResponse(Long id, String authorName, String studentId, String content, String createdAt, String lastEditedAt, Integer likeCount, Boolean isAuthor, Boolean isLiked, Boolean isDeleted, List<String> canAuthority) {
public PostReplyCommentResponse(Long id, String authorName, String studentId, String content, String createdAt, String lastEditedAt, Integer likeCount, Boolean isAuthor, Boolean isLiked, Boolean isDeleted/*, List<String> canAuthority*/) {
this.id = id;
this.authorName = authorName;
this.studentId = studentId;
Expand All @@ -31,7 +31,7 @@ public PostReplyCommentResponse(Long id, String authorName, String studentId, St
this.isAuthor = isAuthor;
this.isLiked = isLiked;
this.isDeleted = isDeleted;
this.canAuthority = canAuthority;
// this.canAuthority = canAuthority;
}

public static PostReplyCommentResponse of(PostReplyComment postReplyComment, User user, Integer likeCount, Boolean isAuthor, Boolean isLiked) {
Expand All @@ -55,7 +55,7 @@ public static PostReplyCommentResponse of(PostReplyComment postReplyComment, Use
.build();
}

public void canAuthority(List<String> canAuthorityList) {
this.canAuthority = canAuthorityList;
}
// public void canAuthority(List<String> canAuthorityList) {
// this.canAuthority = canAuthorityList;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public abstract class PostDetailResDto {
protected String createdAt;
protected String lastEditedAt;
protected Boolean isAuthor;
protected List<String> canAuthority;
protected List<String> allowedAuthorities;

protected PostDetailResDto(Long postId, String categoryName, String authorName, String title, String content, String createdAt, String lastEditedAt, Boolean isAuthor, List<String> canAuthority) {
protected PostDetailResDto(Long postId, String categoryName, String authorName, String title, String content, String createdAt, String lastEditedAt, Boolean isAuthor, List<String> allowedAuthorities) {
this.postId = postId;
this.categoryName = categoryName;
this.authorName = authorName;
Expand All @@ -26,10 +26,10 @@ protected PostDetailResDto(Long postId, String categoryName, String authorName,
this.createdAt = createdAt;
this.lastEditedAt = lastEditedAt;
this.isAuthor = isAuthor;
this.canAuthority = canAuthority;
this.allowedAuthorities = allowedAuthorities;
}

public void canAuthority(List<String> canAuthority) {
this.canAuthority = canAuthority;
public void canAuthority(List<String> allowedAuthorities) {
this.allowedAuthorities = allowedAuthorities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Object validAuthorityOfPost(ProceedingJoinPoint joinPoint, Long userId, S
public Object validCommentAuthorityOfPetitionPost(ProceedingJoinPoint joinPoint, Long userId) throws Throwable {
Object result = joinPoint.proceed();
CommentListResponse commentListRes = (CommentListResponse) result;
postAclHandler.applyPermissionsToCommentList(commentListRes, userId);
commentListRes = postAclHandler.applyPermissionsToCommentList(commentListRes, userId);
return commentListRes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void applyPermissionsToPostDetail(PostDetailRes<?> postDetailRes, Long us
postDetailRes.validAuthority(allowedAuthorities);
}

public void applyPermissionsToCommentList(CommentListResponse commentListRes, Long userId) {
public CommentListResponse applyPermissionsToCommentList(CommentListResponse commentListRes, Long userId) {
List<String> allowedAuthorities = new ArrayList<>();
boolean isLoggedIn = userId != null;

Expand All @@ -57,7 +57,7 @@ public void applyPermissionsToCommentList(CommentListResponse commentListRes, Lo
}
}

commentListRes.validAuthority(allowedAuthorities);
return commentListRes.validAuthorities(allowedAuthorities);
}

private void addPermissionAuthorities(List<String> allowedAuthorities, List<String> deniedAuthorities, Long userId, String boardCode, boolean isLoggedIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
import ussum.homepage.domain.comment.PostComment;
import ussum.homepage.domain.comment.PostCommentRepository;
import ussum.homepage.domain.comment.service.formatter.PostCommentFormatter;
import ussum.homepage.domain.post.PostRepository;
import ussum.homepage.domain.post.exception.PostException;
import ussum.homepage.domain.reaction.exception.PostCommentException;
import ussum.homepage.global.error.exception.InvalidValueException;

import java.util.List;

import static ussum.homepage.global.error.status.ErrorStatus.POST_COMMENT_NOT_FOUND;
import static ussum.homepage.global.error.status.ErrorStatus._BAD_REQUEST;
import static ussum.homepage.global.error.status.ErrorStatus.*;

@Service
@RequiredArgsConstructor
public class PostCommentReader {
private final PostCommentRepository postCommentRepository;
private final PostRepository postRepository;

public Page<PostComment> getPostCommentList(Pageable pageable, Long postId){
return postCommentRepository.findAllByPostId(pageable, postId);
Expand All @@ -37,6 +39,7 @@ public List<PostComment> getCommentListWithPostId(Long postId) {
}

public List<PostComment> getCommentListWithPostIdAndType(Long postId, String type) {
postRepository.findById(postId).orElseThrow(() -> new PostException(POST_NOT_FOUND));
List<PostComment> comments;
switch (type) {
case "인기순":
Expand Down

0 comments on commit f67d66a

Please sign in to comment.