From e7c12a0ca6b59e62936e21689a95681764fca7ce Mon Sep 17 00:00:00 2001 From: yoondgu Date: Tue, 12 Sep 2023 16:19:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Guest=20=EC=A0=84=EC=9A=A9=20?= =?UTF-8?q?=ED=86=A0=ED=94=BD=20=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20DTO?= =?UTF-8?q?=20=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=84=B0=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../topic/application/TopicQueryService.java | 20 ++++++---------- .../dto/response/TopicDetailResponse.java | 24 +++++++++++++++++++ .../topic/dto/response/TopicResponse.java | 17 +++++++++++++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java index 31e86cdb..01394deb 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java @@ -43,7 +43,7 @@ public TopicQueryService( private static List getGuestTopicDetailResponses(List topics) { return topics.stream() - .map(topic -> TopicDetailResponse.of(topic, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)) + .map(TopicDetailResponse::ofGuestQuery) .toList(); } @@ -110,7 +110,7 @@ public TopicDetailResponse findDetailById(AuthMember authMember, Long topicId) { validateReadableTopic(authMember, topic); if (Objects.isNull(authMember.getMemberId())) { - return TopicDetailResponse.of(topic, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE); + return TopicDetailResponse.ofGuestQuery(topic); } Member member = findMemberById(authMember.getMemberId()); @@ -195,7 +195,7 @@ public List findAllTopicsByMemberId(AuthMember authMember, Long m return topicRepository.findByCreatorId(memberId) .stream() .filter(authMember::canRead) - .map(topic -> TopicResponse.from(topic, Boolean.FALSE, Boolean.FALSE)) + .map(TopicResponse::ofGuestQuery) .toList(); } @@ -248,11 +248,8 @@ private List getGuestNewestTopicResponse(AuthMember authMember) { .map(Pin::getTopic) .distinct() .filter(authMember::canRead) - .map(topic -> TopicResponse.from( - topic, - Boolean.FALSE, - Boolean.FALSE - )).toList(); + .map(TopicResponse::ofGuestQuery) + .toList(); } public List findAllBestTopics(AuthMember authMember) { @@ -267,11 +264,8 @@ private List getGuestBestTopicResponse(AuthMember authMember) { .stream() .filter(authMember::canRead) .sorted(Comparator.comparing(Topic::countBookmarks).reversed()) - .map(topic -> TopicResponse.from( - topic, - Boolean.FALSE, - Boolean.FALSE - )).toList(); + .map(TopicResponse::ofGuestQuery) + .toList(); } private List getUserBestTopicResponse(AuthMember authMember) { diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicDetailResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicDetailResponse.java index f1cab3d3..e61e0085 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicDetailResponse.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicDetailResponse.java @@ -20,6 +20,7 @@ public record TopicDetailResponse( LocalDateTime updatedAt, List pins ) { + public static TopicDetailResponse of( Topic topic, Boolean isInAtlas, @@ -47,4 +48,27 @@ public static TopicDetailResponse of( pinResponses ); } + + public static TopicDetailResponse ofGuestQuery(Topic topic) { + List pinResponses = topic.getPins().stream() + .map(PinResponse::from) + .toList(); + + TopicInfo topicInfo = topic.getTopicInfo(); + + return new TopicDetailResponse( + topic.getId(), + topicInfo.getName(), + topicInfo.getDescription(), + topicInfo.getImageUrl(), + topic.getCreator().getMemberInfo().getNickName(), + topic.countPins(), + Boolean.FALSE, + topic.countBookmarks(), + Boolean.FALSE, + Boolean.FALSE, + topic.getUpdatedAt(), + pinResponses + ); + } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicResponse.java index 73165788..f7be63bc 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicResponse.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/dto/response/TopicResponse.java @@ -15,6 +15,7 @@ public record TopicResponse( Boolean isBookmarked, LocalDateTime updatedAt ) { + public static TopicResponse from(Topic topic, Boolean isInAtlas, Boolean isBookmarked) { TopicInfo topicInfo = topic.getTopicInfo(); @@ -31,4 +32,20 @@ public static TopicResponse from(Topic topic, Boolean isInAtlas, Boolean isBookm ); } + public static TopicResponse ofGuestQuery(Topic topic) { + TopicInfo topicInfo = topic.getTopicInfo(); + + return new TopicResponse( + topic.getId(), + topicInfo.getName(), + topicInfo.getImageUrl(), + topic.getCreator().getMemberInfo().getNickName(), + topic.countPins(), + Boolean.FALSE, + topic.countBookmarks(), + Boolean.FALSE, + topic.getUpdatedAt() + ); + } + }