From 9dee82d56f55ce3367997bb6ff9cfbbff0b3a451 Mon Sep 17 00:00:00 2001 From: SCY Date: Tue, 13 Aug 2024 19:57:01 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=EB=8C=93=EA=B8=80=EB=B0=A9=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=EC=A0=90=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/zzang/chongdae/comment/service/CommentService.java | 3 --- .../chongdae/offering/repository/entity/OfferingEntity.java | 4 ---- 2 files changed, 7 deletions(-) diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index f61e44d6..7ec7a46b 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -11,7 +11,6 @@ import com.zzang.chongdae.comment.service.dto.CommentRoomAllResponseItem; import com.zzang.chongdae.comment.service.dto.CommentSaveRequest; import com.zzang.chongdae.global.exception.MarketException; -import com.zzang.chongdae.member.repository.MemberRepository; import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.domain.OfferingWithRole; import com.zzang.chongdae.offering.exception.OfferingErrorCode; @@ -28,7 +27,6 @@ public class CommentService { private final CommentRepository commentRepository; - private final MemberRepository memberRepository; private final OfferingRepository offeringRepository; public Long saveComment(CommentSaveRequest request, MemberEntity member) { @@ -43,7 +41,6 @@ public Long saveComment(CommentSaveRequest request, MemberEntity member) { public CommentRoomAllResponse getAllCommentRoom(MemberEntity member) { List offeringsWithRole = offeringRepository.findAllWithRoleByMember(member); List responseItems = offeringsWithRole.stream() - .filter(offeringWithRole -> offeringWithRole.getOffering().hasParticipant()) .map(this::toCommentRoomAllResponseItem) .toList(); return new CommentRoomAllResponse(responseItems); diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index a8635c45..19649332 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -122,10 +122,6 @@ public OfferingMeeting toOfferingMeeting() { return new OfferingMeeting(deadline, meetingAddress, meetingAddressDetail, meetingAddressDong); } - public boolean hasParticipant() { - return currentCount > INITIAL_COUNT; - } - public boolean isStatusGrouping() { return this.roomStatus.isGrouping(); } From b46e32b025c451f0a28611fcff29523712c310d8 Mon Sep 17 00:00:00 2001 From: SCY Date: Tue, 13 Aug 2024 20:27:43 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=8F=84=EB=A9=94=EC=9D=B8=20OfferingWithRole=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chongdae/comment/service/CommentService.java | 15 ++++++--------- .../service/dto/CommentRoomAllResponseItem.java | 4 ++-- .../offering/domain/OfferingWithRole.java | 14 -------------- .../offering/repository/OfferingRepository.java | 5 ++--- .../repository/entity/OfferingEntity.java | 6 +++++- 5 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingWithRole.java diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index 7ec7a46b..3d9157de 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -12,7 +12,6 @@ import com.zzang.chongdae.comment.service.dto.CommentSaveRequest; import com.zzang.chongdae.global.exception.MarketException; import com.zzang.chongdae.member.repository.entity.MemberEntity; -import com.zzang.chongdae.offering.domain.OfferingWithRole; import com.zzang.chongdae.offering.exception.OfferingErrorCode; import com.zzang.chongdae.offering.repository.OfferingRepository; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; @@ -39,21 +38,19 @@ public Long saveComment(CommentSaveRequest request, MemberEntity member) { } public CommentRoomAllResponse getAllCommentRoom(MemberEntity member) { - List offeringsWithRole = offeringRepository.findAllWithRoleByMember(member); - List responseItems = offeringsWithRole.stream() - .map(this::toCommentRoomAllResponseItem) + List commentRooms = offeringRepository.findCommentRoomsByMember(member); + List responseItems = commentRooms.stream() + .map(commentsRoom -> toCommentRoomAllResponseItem(commentsRoom, member)) .toList(); return new CommentRoomAllResponse(responseItems); } - private CommentRoomAllResponseItem toCommentRoomAllResponseItem(OfferingWithRole offeringWithRole) { - OfferingEntity offering = offeringWithRole.getOffering(); - OfferingMemberRole role = offeringWithRole.getRole(); + private CommentRoomAllResponseItem toCommentRoomAllResponseItem(OfferingEntity offering, MemberEntity member) { return new CommentRoomAllResponseItem( offering.getId(), offering.getTitle(), - toCommentLatestResponse(offering), - role.isProposer()); + offering.isProposedBy(member), + toCommentLatestResponse(offering)); } private CommentLatestResponse toCommentLatestResponse(OfferingEntity offering) { diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java index ca4fcc1d..f306797d 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java @@ -2,6 +2,6 @@ public record CommentRoomAllResponseItem(Long offeringId, String offeringTitle, - CommentLatestResponse latestComment, - Boolean isProposer) { + Boolean isProposer, + CommentLatestResponse latestComment) { } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingWithRole.java b/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingWithRole.java deleted file mode 100644 index ab58d5cb..00000000 --- a/backend/src/main/java/com/zzang/chongdae/offering/domain/OfferingWithRole.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.zzang.chongdae.offering.domain; - -import com.zzang.chongdae.offering.repository.entity.OfferingEntity; -import com.zzang.chongdae.offeringmember.domain.OfferingMemberRole; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class OfferingWithRole { - - private final OfferingEntity offering; - private final OfferingMemberRole role; -} diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java index 5fef7a15..80e1cfba 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/OfferingRepository.java @@ -1,7 +1,6 @@ package com.zzang.chongdae.offering.repository; import com.zzang.chongdae.member.repository.entity.MemberEntity; -import com.zzang.chongdae.offering.domain.OfferingWithRole; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import java.time.LocalDateTime; import java.util.List; @@ -12,12 +11,12 @@ public interface OfferingRepository extends JpaRepository { @Query(""" - SELECT new com.zzang.chongdae.offering.domain.OfferingWithRole(o, om.role) + SELECT o FROM OfferingEntity as o JOIN OfferingMemberEntity as om ON o.id = om.offering.id WHERE om.member = :member """) - List findAllWithRoleByMember(MemberEntity member); + List findCommentRoomsByMember(MemberEntity member); @Query(""" SELECT o diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index 19649332..cc313d9c 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -126,8 +126,12 @@ public boolean isStatusGrouping() { return this.roomStatus.isGrouping(); } + public boolean isProposedBy(MemberEntity other) { + return this.member.equals(other); + } + public boolean isNotProposedBy(MemberEntity other) { - return !this.member.equals(other); + return !isProposedBy(other); } public void updateMeeting(OfferingMeeting offeringMeeting) { From 6549825833945bf85d80d967d6e2aaf85d5450a0 Mon Sep 17 00:00:00 2001 From: SCY Date: Tue, 13 Aug 2024 21:05:56 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=8F=84=EB=A9=94=EC=9D=B8=20CommentWithRole=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/domain/CommentWithRole.java | 14 ----------- .../comment/repository/CommentRepository.java | 13 +--------- .../comment/service/CommentService.java | 24 ++++++++----------- .../service/dto/CommentAllResponseItem.java | 7 ++++++ .../repository/entity/MemberEntity.java | 4 ---- 5 files changed, 18 insertions(+), 44 deletions(-) delete mode 100644 backend/src/main/java/com/zzang/chongdae/comment/domain/CommentWithRole.java diff --git a/backend/src/main/java/com/zzang/chongdae/comment/domain/CommentWithRole.java b/backend/src/main/java/com/zzang/chongdae/comment/domain/CommentWithRole.java deleted file mode 100644 index b81ae705..00000000 --- a/backend/src/main/java/com/zzang/chongdae/comment/domain/CommentWithRole.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.zzang.chongdae.comment.domain; - -import com.zzang.chongdae.comment.repository.entity.CommentEntity; -import com.zzang.chongdae.offeringmember.domain.OfferingMemberRole; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class CommentWithRole { - - private final CommentEntity comment; - private final OfferingMemberRole role; -} diff --git a/backend/src/main/java/com/zzang/chongdae/comment/repository/CommentRepository.java b/backend/src/main/java/com/zzang/chongdae/comment/repository/CommentRepository.java index cee83730..004835a4 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/repository/CommentRepository.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/repository/CommentRepository.java @@ -1,25 +1,14 @@ package com.zzang.chongdae.comment.repository; -import com.zzang.chongdae.comment.domain.CommentWithRole; import com.zzang.chongdae.comment.repository.entity.CommentEntity; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; public interface CommentRepository extends JpaRepository { - @Query(""" - SELECT new com.zzang.chongdae.comment.domain.CommentWithRole(c, om.role) - FROM CommentEntity as c JOIN OfferingMemberEntity as om - ON c.offering = om.offering AND c.member = om.member - WHERE om.offering = :offering - ORDER BY c.createdAt - """) - List findAllWithRoleByOffering(OfferingEntity offering); + List findAllByOfferingOrderByCreatedAt(OfferingEntity offering); Optional findTopByOfferingOrderByCreatedAtDesc(OfferingEntity offering); - - Boolean existsByOffering(OfferingEntity offering); } diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index 3d9157de..d2358104 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -1,11 +1,9 @@ package com.zzang.chongdae.comment.service; -import com.zzang.chongdae.comment.domain.CommentWithRole; import com.zzang.chongdae.comment.repository.CommentRepository; import com.zzang.chongdae.comment.repository.entity.CommentEntity; import com.zzang.chongdae.comment.service.dto.CommentAllResponse; import com.zzang.chongdae.comment.service.dto.CommentAllResponseItem; -import com.zzang.chongdae.comment.service.dto.CommentCreatedAtResponse; import com.zzang.chongdae.comment.service.dto.CommentLatestResponse; import com.zzang.chongdae.comment.service.dto.CommentRoomAllResponse; import com.zzang.chongdae.comment.service.dto.CommentRoomAllResponseItem; @@ -15,7 +13,6 @@ import com.zzang.chongdae.offering.exception.OfferingErrorCode; import com.zzang.chongdae.offering.repository.OfferingRepository; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; -import com.zzang.chongdae.offeringmember.domain.OfferingMemberRole; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -64,23 +61,22 @@ public CommentAllResponse getAllComment(Long offeringId, MemberEntity member) { OfferingEntity offering = offeringRepository.findById(offeringId) .orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND)); - List commentsWithRole = commentRepository.findAllWithRoleByOffering(offering); - List responseItems = commentsWithRole.stream() - .map(commentWithRole -> toCommentAllResponseItem(commentWithRole, member.getId())) + List comments = commentRepository.findAllByOfferingOrderByCreatedAt(offering); + List responseItems = comments.stream() + .map(comment -> toCommentAllResponseItem(comment, member)) .toList(); return new CommentAllResponse(responseItems); } - private CommentAllResponseItem toCommentAllResponseItem(CommentWithRole commentWithRole, long loginMemberId) { - CommentEntity comment = commentWithRole.getComment(); - OfferingMemberRole role = commentWithRole.getRole(); - MemberEntity member = comment.getMember(); + private CommentAllResponseItem toCommentAllResponseItem(CommentEntity comment, MemberEntity member) { + MemberEntity commentWriter = comment.getMember(); + OfferingEntity offering = comment.getOffering(); return new CommentAllResponseItem( comment.getId(), - new CommentCreatedAtResponse(comment.getCreatedAt()), + comment.getCreatedAt(), comment.getContent(), - member.getNickname(), - role.isProposer(), - member.isSameMember(loginMemberId)); + commentWriter.getNickname(), + offering.isProposedBy(commentWriter), + commentWriter.equals(member)); } } diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java index dd403c7c..3cbae7fe 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java @@ -1,9 +1,16 @@ package com.zzang.chongdae.comment.service.dto; +import java.time.LocalDateTime; + public record CommentAllResponseItem(Long commentId, CommentCreatedAtResponse createdAt, String content, String nickname, Boolean isProposer, Boolean isMine) { + + public CommentAllResponseItem(Long commentId, LocalDateTime createdAt, String content, + String nickname, Boolean isProposer, Boolean isMine) { + this(commentId, new CommentCreatedAtResponse(createdAt), content, nickname, isProposer, isMine); + } } diff --git a/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java index ff03b74c..381e174f 100644 --- a/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java @@ -36,8 +36,4 @@ public class MemberEntity extends BaseTimeEntity { public MemberEntity(String nickname, String password) { this(null, nickname, password); } - - public boolean isSameMember(Long memberId) { - return this.id.equals(memberId); - } } From eb51dc0e0e9aa6194eedc9f6aa8961f6c1312a49 Mon Sep 17 00:00:00 2001 From: SCY Date: Wed, 14 Aug 2024 13:49:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20=EB=8C=93=EA=B8=80=EC=9D=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EC=9E=90=20=ED=99=95=EC=9D=B8=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/entity/CommentEntity.java | 4 ++++ .../comment/service/CommentService.java | 14 +------------- .../service/dto/CommentAllResponseItem.java | 17 +++++++++++------ .../member/repository/entity/MemberEntity.java | 4 ++++ .../repository/entity/OfferingEntity.java | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java b/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java index 28d48244..8cacf471 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/repository/entity/CommentEntity.java @@ -42,4 +42,8 @@ public class CommentEntity extends BaseTimeEntity { public CommentEntity(MemberEntity member, OfferingEntity offering, String content) { this(null, member, offering, content); } + + public boolean isOwnedBy(MemberEntity other) { + return this.member.isSame(other); + } } diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index d2358104..7952a09a 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -63,20 +63,8 @@ public CommentAllResponse getAllComment(Long offeringId, MemberEntity member) { List comments = commentRepository.findAllByOfferingOrderByCreatedAt(offering); List responseItems = comments.stream() - .map(comment -> toCommentAllResponseItem(comment, member)) + .map(comment -> new CommentAllResponseItem(comment, member)) .toList(); return new CommentAllResponse(responseItems); } - - private CommentAllResponseItem toCommentAllResponseItem(CommentEntity comment, MemberEntity member) { - MemberEntity commentWriter = comment.getMember(); - OfferingEntity offering = comment.getOffering(); - return new CommentAllResponseItem( - comment.getId(), - comment.getCreatedAt(), - comment.getContent(), - commentWriter.getNickname(), - offering.isProposedBy(commentWriter), - commentWriter.equals(member)); - } } diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java index 3cbae7fe..0dd1a0d0 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentAllResponseItem.java @@ -1,16 +1,21 @@ package com.zzang.chongdae.comment.service.dto; -import java.time.LocalDateTime; +import com.zzang.chongdae.comment.repository.entity.CommentEntity; +import com.zzang.chongdae.member.repository.entity.MemberEntity; public record CommentAllResponseItem(Long commentId, CommentCreatedAtResponse createdAt, String content, String nickname, - Boolean isProposer, - Boolean isMine) { + boolean isProposer, + boolean isMine) { - public CommentAllResponseItem(Long commentId, LocalDateTime createdAt, String content, - String nickname, Boolean isProposer, Boolean isMine) { - this(commentId, new CommentCreatedAtResponse(createdAt), content, nickname, isProposer, isMine); + public CommentAllResponseItem(CommentEntity comment, MemberEntity member) { + this(comment.getId(), + new CommentCreatedAtResponse(comment.getCreatedAt()), + comment.getContent(), + comment.getMember().getNickname(), + comment.getOffering().isProposedBy(comment.getMember()), + comment.isOwnedBy(member)); } } diff --git a/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java index 381e174f..e840affb 100644 --- a/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/member/repository/entity/MemberEntity.java @@ -36,4 +36,8 @@ public class MemberEntity extends BaseTimeEntity { public MemberEntity(String nickname, String password) { this(null, nickname, password); } + + public boolean isSame(MemberEntity other) { + return this.equals(other); + } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java index cc313d9c..fc6968b1 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/repository/entity/OfferingEntity.java @@ -127,7 +127,7 @@ public boolean isStatusGrouping() { } public boolean isProposedBy(MemberEntity other) { - return this.member.equals(other); + return this.member.isSame(other); } public boolean isNotProposedBy(MemberEntity other) { From d4265f487e8b7c493e38e0e03b1f2d455a8f3483 Mon Sep 17 00:00:00 2001 From: SCY Date: Wed, 14 Aug 2024 14:06:39 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=EB=8C=93=EA=B8=80=EB=B0=A9=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20dto=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chongdae/comment/service/CommentService.java | 13 +++---------- .../service/dto/CommentRoomAllResponseItem.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index 7952a09a..4da6fe0c 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -43,18 +43,11 @@ public CommentRoomAllResponse getAllCommentRoom(MemberEntity member) { } private CommentRoomAllResponseItem toCommentRoomAllResponseItem(OfferingEntity offering, MemberEntity member) { - return new CommentRoomAllResponseItem( - offering.getId(), - offering.getTitle(), - offering.isProposedBy(member), - toCommentLatestResponse(offering)); - } - - private CommentLatestResponse toCommentLatestResponse(OfferingEntity offering) { - Optional rawComment = commentRepository.findTopByOfferingOrderByCreatedAtDesc(offering); - return rawComment + Optional comment = commentRepository.findTopByOfferingOrderByCreatedAtDesc(offering); + CommentLatestResponse commentLatestResponse = comment .map(CommentLatestResponse::new) .orElseGet(() -> new CommentLatestResponse(null, null)); + return new CommentRoomAllResponseItem(offering, member, commentLatestResponse); } public CommentAllResponse getAllComment(Long offeringId, MemberEntity member) { diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java index f306797d..f68c5e1b 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomAllResponseItem.java @@ -1,7 +1,19 @@ package com.zzang.chongdae.comment.service.dto; +import com.zzang.chongdae.member.repository.entity.MemberEntity; +import com.zzang.chongdae.offering.repository.entity.OfferingEntity; + public record CommentRoomAllResponseItem(Long offeringId, String offeringTitle, Boolean isProposer, CommentLatestResponse latestComment) { + + public CommentRoomAllResponseItem(OfferingEntity offering, + MemberEntity member, + CommentLatestResponse latestComment) { + this(offering.getId(), + offering.getTitle(), + offering.isProposedBy(member), + latestComment); + } }