Skip to content

Commit

Permalink
fix: #31 DTO 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ehs208 committed Nov 13, 2024
1 parent 7eb51b4 commit bbb4c46
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
@NoArgsConstructor
public class ArticleResponseDto {
private UUID articleId;
private Long writerId;
private String customId;
private String userName;
private String content;
private DeletedStatus deletedStatus;
private List<String> hashtags;
Expand All @@ -34,11 +35,13 @@ public class ArticleResponseDto {
private boolean owner;

@Builder
private ArticleResponseDto(UUID articleId, Long writerId, String content, DeletedStatus deletedStatus,
List<String> hashtags, UUID rePostId, List<String> mediaUrls, List<CommentResponseDto> comments,
int viewCnt, long rePostCnt, long likeCnt, long commentCnt, boolean owner) {
private ArticleResponseDto(UUID articleId, String userName, String customId, String content,
DeletedStatus deletedStatus,
List<String> hashtags, UUID rePostId, List<String> mediaUrls, List<CommentResponseDto> comments,
int viewCnt, long rePostCnt, long likeCnt, long commentCnt, boolean owner) {
this.articleId = articleId;
this.writerId = writerId;
this.userName = userName;
this.customId = customId;
this.content = content;
this.deletedStatus = deletedStatus;
this.hashtags = hashtags;
Expand All @@ -52,12 +55,14 @@ private ArticleResponseDto(UUID articleId, Long writerId, String content, Delete
this.comments = comments;
}

public static ArticleResponseDto from(Article article, boolean isOwner, ArticleStatsDto stats, Map<UUID, CommentStatsDto> replyStatsMap) {
public static ArticleResponseDto from(Article article, boolean isOwner, ArticleStatsDto stats,
Map<UUID, CommentStatsDto> replyStatsMap) {
return ArticleResponseDto.builder()
.articleId(article.getArticleId())
.content(article.getContent())
.deletedStatus(article.getDeletedStatus())
.writerId(article.getWriter().getUserId())
.userName(article.getWriter().getUserName())
.customId(article.getWriter().getCustomId())
.hashtags(article.getHashtags() != null ? article.getHashtags()
.stream()
.map(Hashtag::getContent)
Expand All @@ -69,9 +74,11 @@ public static ArticleResponseDto from(Article article, boolean isOwner, ArticleS
.collect(Collectors.toList()) : null)
.comments(article.getComments() != null ? article.getComments()
.stream()
.filter(comment -> comment != null && comment.getDeletedStatus() == DeletedStatus.NOT_DELETED) // null 및 삭제된 댓글 필터링
.filter(comment -> comment != null
&& comment.getDeletedStatus() == DeletedStatus.NOT_DELETED) // null 및 삭제된 댓글 필터링
.map(comment -> {
CommentStatsDto commentStats = replyStatsMap.getOrDefault(comment.getCommentId(), CommentStatsDto.from(0, 0));
CommentStatsDto commentStats = replyStatsMap.getOrDefault(comment.getCommentId(),
CommentStatsDto.from(0, 0));
boolean isCommentOwner = comment.getWriter().getUserId().equals(article.getWriter().getUserId());
return CommentResponseDto.from(comment, isCommentOwner, commentStats, replyStatsMap, 1); // 깊이 1로 제한
})
Expand All @@ -89,7 +96,8 @@ public static ArticleResponseDto fromWithoutComments(Article article, boolean is
.articleId(article.getArticleId())
.content(article.getContent())
.deletedStatus(article.getDeletedStatus())
.writerId(article.getWriter().getUserId())
.userName(article.getWriter().getUserName())
.customId(article.getWriter().getCustomId())
.hashtags(article.getHashtags() != null ? article.getHashtags()
.stream()
.map(Hashtag::getContent)
Expand Down

0 comments on commit bbb4c46

Please sign in to comment.