From 7942eb662da8cdc8e88727a8f676c76920ff0ec3 Mon Sep 17 00:00:00 2001 From: ls-rain Date: Tue, 5 Aug 2025 22:13:29 +0900 Subject: [PATCH] [feat/#162] Refactoring CommunityDetail ResponseDTO --- .../example/helloworldmvc/converter/CommunityConverter.java | 3 ++- .../example/helloworldmvc/service/CommunityServiceImpl.java | 6 +++++- .../example/helloworldmvc/web/dto/CommunityResponseDTO.java | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java index 8a2fc06..72b4e87 100644 --- a/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java +++ b/src/main/java/com/example/helloworldmvc/converter/CommunityConverter.java @@ -51,7 +51,7 @@ public static CommunityResponseDTO.PostDTO toPostDTO(Community community, Long c .build(); } - public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page commentList){ + public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community community, Page commentList, Boolean isOwner){ List list = new ArrayList(); if(!community.getFileList().isEmpty()){ community.getFileList().stream().forEach(file -> { @@ -64,6 +64,7 @@ public static CommunityResponseDTO.PostDetailDTO toPostDetailDTO(Community commu .content(community.getContent()) .communityWriterEmail(community.getUser().getEmail()) .created_at(community.getCreatedAt()) + .isOwner(isOwner) .fileList(list) .commentDTOList(comments) .build(); diff --git a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java index 62924c0..5eb62d1 100644 --- a/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java +++ b/src/main/java/com/example/helloworldmvc/service/CommunityServiceImpl.java @@ -65,7 +65,11 @@ public CommunityResponseDTO.PostDetailDTO getCommunityDetail(String userId, Long int end = Math.min((start + pageRequest.getPageSize()), commentList.size()); List subList = commentList.subList(start, end); Page commentPage = new PageImpl<>(subList, pageRequest, commentList.size()); - return CommunityConverter.toPostDetailDTO(community, commentPage); + boolean isOwner = false; + if(community.getUser().getEmail().equals(user.getEmail())) { + isOwner = true; + } + return CommunityConverter.toPostDetailDTO(community, commentPage, isOwner); } @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 f6c68c1..9016524 100644 --- a/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java +++ b/src/main/java/com/example/helloworldmvc/web/dto/CommunityResponseDTO.java @@ -49,6 +49,7 @@ public static class PostDetailDTO{ LocalDateTime created_at; List fileList; List commentDTOList; + Boolean isOwner; } @Builder