Skip to content

Commit

Permalink
[refactor] canAuthority 대댓글 반환 값에도 포함
Browse files Browse the repository at this point in the history
  • Loading branch information
chahyunsoo committed Sep 22, 2024
1 parent 90e200d commit b3bc923
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public static CommentListResponse of(List<PostCommentResponse> postCommentRespon
}

public void validAuthority(List<String> canAuthorityList) {
postComments.forEach(postComment -> postComment.canAuthority(canAuthorityList));
postComments.forEach(postComment -> {
postComment.canAuthority(canAuthorityList);
postComment.getPostReplyComments().stream().forEach(
postReplyComment -> postReplyComment.canAuthority(canAuthorityList)
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static PostCommentResponse of(PostComment postComment, User user, String
.createdAt(postComment.getCreatedAt())
.lastEditedAt(postComment.getLastEditedAt())
.likeCount(likeCount)
.isAuthor(isAuthor)
.isLiked(isLiked)
.isDeleted(postComment.getIsDeleted())
.postReplyComments(postReplyComments)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,61 @@
package ussum.homepage.application.comment.service.dto.response;

import lombok.Builder;
import ussum.homepage.domain.comment.PostReplyComment;
import ussum.homepage.domain.user.User;

public record PostReplyCommentResponse(
Long id,
String authorName,
String studentId,
String content,
String createdAt,
String lastEditedAt,
Integer likeCount,
Boolean isAuthor,
Boolean isLiked,
Boolean isDeleted
) {
import java.util.List;

public class PostReplyCommentResponse {
public Long id;
public String authorName;
public String studentId;
public String content;
public String createdAt;
public String lastEditedAt;
public Integer likeCount;
public Boolean isAuthor;
public Boolean isLiked;
public Boolean isDeleted;
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) {
this.id = id;
this.authorName = authorName;
this.studentId = studentId;
this.content = content;
this.createdAt = createdAt;
this.lastEditedAt = lastEditedAt;
this.likeCount = likeCount;
this.isAuthor = isAuthor;
this.isLiked = isLiked;
this.isDeleted = isDeleted;
this.canAuthority = canAuthority;
}

public static PostReplyCommentResponse of(PostReplyComment postReplyComment, User user, Integer likeCount, Boolean isAuthor, Boolean isLiked) {
String studentId = user.getStudentId();
String content = postReplyComment.getContent();
if (postReplyComment.getIsDeleted().equals(true)) {
studentId = "삭제된 사용자입니다.";
content = "삭제된 댓글입니다.";
}
return new PostReplyCommentResponse(
postReplyComment.getId(),
user.getName(),
studentId,
content,
postReplyComment.getCreatedAt(),
postReplyComment.getLastEditedAt(),
likeCount,
isAuthor,
isLiked,
postReplyComment.getIsDeleted()
);
return PostReplyCommentResponse.builder()
.id(postReplyComment.getId())
.authorName(user.getName())
.studentId(studentId)
.content(content)
.createdAt(postReplyComment.getCreatedAt())
.lastEditedAt(postReplyComment.getLastEditedAt())
.likeCount(likeCount)
.isAuthor(isAuthor)
.isLiked(isLiked)
.isDeleted(postReplyComment.getIsDeleted())
.build();
}

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

0 comments on commit b3bc923

Please sign in to comment.