From 838ec64d37c45c81de80205063bf9502afde74b2 Mon Sep 17 00:00:00 2001 From: Dora Choo Date: Tue, 23 Jul 2024 21:17:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=B5=EB=AA=A8=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API=EC=97=90=20=EC=B0=B8=EC=97=AC?= =?UTF-8?q?=EC=9E=90=20=EB=AA=A9=EB=A1=9D=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offering/service/OfferingService.java | 9 ++++++++- .../service/dto/OfferingDetailResponse.java | 19 ++++++++++++------- .../repository/OfferingMemberRepository.java | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java index 3193380a8..14f7669ca 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java @@ -1,5 +1,7 @@ package com.zzang.chongdae.offering.service; +import com.zzang.chongdae.member.repository.MemberRepository; +import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.domain.OfferingPrice; import com.zzang.chongdae.offering.domain.OfferingStatus; import com.zzang.chongdae.offering.repository.OfferingRepository; @@ -20,6 +22,7 @@ public class OfferingService { private final OfferingRepository offeringRepository; private final OfferingMemberRepository offeringMemberRepository; + private final MemberRepository memberRepository; public OfferingDetailResponse getOfferingDetail(Long id) { OfferingEntity offering = offeringRepository.findById(id) @@ -29,7 +32,11 @@ public OfferingDetailResponse getOfferingDetail(Long id) { int currentCount = offeringMemberRepository.countByOffering(offering); OfferingStatus offeringStatus = offering.toOfferingStatus(currentCount); - return new OfferingDetailResponse(offering, offeringPrice, offeringStatus); + MemberEntity member = memberRepository.findById(1L) + .orElseThrow(); // TODO: 로그인 추가하면 교체 필요 + Boolean isParticipated = offeringMemberRepository.existsByOfferingAndMember(offering, member); + + return new OfferingDetailResponse(offering, offeringPrice, offeringStatus, isParticipated); } public OfferingAllResponse getAllOffering(Long lastId, Integer pageSize) { diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java index 734db7b0a..bd5a37f22 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingDetailResponse.java @@ -8,8 +8,6 @@ public record OfferingDetailResponse(Long id, String title, - String nickname, - Long memberId, String productUrl, String meetingAddress, String meetingAddressDetail, @@ -20,13 +18,17 @@ public record OfferingDetailResponse(Long id, String thumbnailUrl, Integer dividedPrice, Integer totalPrice, - OfferingCondition condition) { + OfferingCondition condition, + Long memberId, + String nickname, + Boolean isParticipated) { - public OfferingDetailResponse(OfferingEntity offering, OfferingPrice offeringPrice, OfferingStatus offeringStatus) { + public OfferingDetailResponse(OfferingEntity offering, + OfferingPrice offeringPrice, + OfferingStatus offeringStatus, + Boolean isParticipated) { this(offering.getId(), offering.getTitle(), - offering.getMember().getNickname(), - offering.getMember().getId(), offering.getProductUrl(), offering.getMeetingAddress(), offering.getMeetingAddressDetail(), @@ -37,7 +39,10 @@ public OfferingDetailResponse(OfferingEntity offering, OfferingPrice offeringPri offering.getThumbnailUrl(), offeringPrice.calculateDividedPrice().intValue(), offering.getTotalPrice().intValue(), - offeringStatus.decideOfferingCondition() + offeringStatus.decideOfferingCondition(), + offering.getMember().getId(), + offering.getMember().getNickname(), + isParticipated ); } } diff --git a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java index d235ee943..a3f161d21 100644 --- a/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java +++ b/backend/src/main/java/com/zzang/chongdae/offeringmember/repository/OfferingMemberRepository.java @@ -1,5 +1,6 @@ package com.zzang.chongdae.offeringmember.repository; +import com.zzang.chongdae.member.repository.entity.MemberEntity; import com.zzang.chongdae.offering.repository.entity.OfferingEntity; import com.zzang.chongdae.offeringmember.repository.entity.OfferingMemberEntity; import org.springframework.data.jpa.repository.JpaRepository; @@ -7,4 +8,6 @@ public interface OfferingMemberRepository extends JpaRepository { int countByOffering(OfferingEntity offering); + + Boolean existsByOfferingAndMember(OfferingEntity offering, MemberEntity member); }