Skip to content

Commit

Permalink
feat: 공모 상세 조회 API에 참여자 목록 필드 추가 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChooSeoyeon authored Jul 23, 2024
1 parent 4b8322b commit 838ec64
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

public record OfferingDetailResponse(Long id,
String title,
String nickname,
Long memberId,
String productUrl,
String meetingAddress,
String meetingAddressDetail,
Expand All @@ -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(),
Expand All @@ -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
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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;

public interface OfferingMemberRepository extends JpaRepository<OfferingMemberEntity, Long> {

int countByOffering(OfferingEntity offering);

Boolean existsByOfferingAndMember(OfferingEntity offering, MemberEntity member);
}

0 comments on commit 838ec64

Please sign in to comment.