diff --git a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java index df233c2..1e93b03 100644 --- a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java +++ b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java @@ -2,6 +2,7 @@ import com.example.helloworldmvc.domain.Comment; import com.example.helloworldmvc.domain.Community; +import com.example.helloworldmvc.domain.User; import com.example.helloworldmvc.domain.enums.CommunityCategory; import com.example.helloworldmvc.web.dto.CommunityRequestDTO; import com.example.helloworldmvc.web.dto.CommunityResponseDTO; @@ -51,18 +52,22 @@ public static CommunityResponseDTO.PostDTO toPostDTO(Community community, Long c .build(); } - public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page commentList, Boolean isOwner){ + public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page commentList, Boolean isOwner, String userId){ List list = new ArrayList(); if(!community.getFileList().isEmpty()){ community.getFileList().stream().forEach(file -> { list.add(FileConverter.toFileDetailRes(file.getUrl(), file.getFileType())); }); } - List comments = commentList.stream().map(CommunityConverter::toCommentDTO).toList(); + List comments = commentList.stream().map(comment -> { + if(comment.getUser().getEmail().equals(userId)){ + return toCommentDTO(comment, Boolean.TRUE); + } + return toCommentDTO(comment, Boolean.FALSE); + }).toList(); return CommunityResponseDTO.PostDetailDTO.builder() .title(community.getTitle()) .content(community.getContent()) - .communityWriterEmail(community.getUser().getEmail()) .created_at(community.getCreatedAt()) .isOwner(isOwner) .fileList(list) @@ -70,12 +75,14 @@ public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community commu .build(); } - public static CommunityResponseDTO.CommentDTO toCommentDTO(Comment comment){ + public static CommunityResponseDTO.CommentDTO toCommentDTO(Comment comment, Boolean isOwner){ return CommunityResponseDTO.CommentDTO.builder() .anonymousName(comment.getAnonymous()) + .commentId(comment.getId()) .commentWriterEmail(comment.getUser().getEmail()) .created_at(comment.getCreatedAt()) .content(comment.getContent()) + .isOwner(isOwner) .build(); } public static CommunityCategory toCommunityCategory(Long categoryId){ diff --git a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java index 44bfe02..c409738 100644 --- a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java +++ b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java @@ -69,7 +69,7 @@ public CommunityResponseDTO.PostDetailDTO getCommunityDetail(String userId, Long if(community.getUser().getEmail().equals(user.getEmail())) { isOwner = true; } - return CommunityConverter.toPostDetailDTO(community, commentPage, isOwner); + return CommunityConverter.toPostDetailDTO(community, commentPage, isOwner, userId); } @Override diff --git a/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java b/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java index 0befe5a..f4072a3 100644 --- a/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java +++ b/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java @@ -45,7 +45,6 @@ public static class PostDTO{ public static class PostDetailDTO{ String title; String content; - String communityWriterEmail; LocalDateTime created_at; List fileList; List commentDTOList; @@ -58,9 +57,11 @@ public static class PostDetailDTO{ @AllArgsConstructor public static class CommentDTO{ Long anonymousName; + Long commentId; String commentWriterEmail; LocalDateTime created_at; String content; + Boolean isOwner; } @Builder