Skip to content

Commit

Permalink
feat: 이미 참여한 공모에 참여 못하게 예외 처리 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChooSeoyeon authored Jul 24, 2024
1 parent 9313bbc commit e548a1a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
2 changes: 1 addition & 1 deletion backend/http/offering-member.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Content-Type: application/json

{
"memberId": 2,
"offeringId": 1
"offeringId": 2
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.zzang.chongdae.common.repository.entity.BaseTimeEntity;
import com.zzang.chongdae.member.repository.entity.MemberEntity;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingProposer;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -73,8 +72,4 @@ public OfferingPrice toOfferingPrice() {
public OfferingStatus toOfferingStatus(int currentCount) {
return new OfferingStatus(deadline, totalCount, isManualConfirmed, currentCount);
}

public OfferingProposer toOfferingProposer() {
return new OfferingProposer(member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.zzang.chongdae.member.repository.MemberRepository;
import com.zzang.chongdae.member.repository.entity.MemberEntity;
import com.zzang.chongdae.offering.domain.OfferingProposer;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import com.zzang.chongdae.offering.repository.OfferingRepository;
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;
Expand All @@ -28,34 +27,30 @@ public Long participate(ParticipationRequest request) {
.orElseThrow(); // TODO: 예외처리 하기
OfferingEntity offering = offeringRepository.findById(request.offeringId())
.orElseThrow();// TODO: 예외처리 하기

int currentCount = offeringMemberRepository.countByOffering(offering);
OfferingStatus offeringStatus = offering.toOfferingStatus(currentCount);
OfferingProposer offeringProposer = offering.toOfferingProposer();
validateParticipate(offeringStatus, offeringProposer, member);
validateParticipate(offering, member);

OfferingMemberEntity offeringMember = new OfferingMemberEntity(
member, offering, OfferingMemberRole.PARTICIPANT);
offeringMemberRepository.save(offeringMember);

return offeringMember.getId();
}

private void validateParticipate(
OfferingStatus offeringStatus, OfferingProposer offeringProposer, MemberEntity member) {
validateClosed(offeringStatus);
validateProposer(offeringProposer, member); // TODO: 이미 참여한 공모에 참여 못하게 추가로 막아야 함
private void validateParticipate(OfferingEntity offering, MemberEntity member) {
validateClosed(offering);
validateDuplicate(offering, member);
}

private void validateClosed(OfferingStatus offeringStatus) {
private void validateClosed(OfferingEntity offering) {
int currentCount = offeringMemberRepository.countByOffering(offering);
OfferingStatus offeringStatus = offering.toOfferingStatus(currentCount);
if (offeringStatus.isClosed()) {
throw new IllegalArgumentException("아이고 못들어가요 ㅜㅜ"); // TODO: 예외처리 하기
}
}

private void validateProposer(OfferingProposer offeringProposer, MemberEntity member) {
if (offeringProposer.isProposer(member)) {
throw new IllegalArgumentException("공모자는 참여할 수 없어요 ㅜㅜ"); // TODO: 예외처리 하기
private void validateDuplicate(OfferingEntity offering, MemberEntity member) {
if (offeringMemberRepository.existsByOfferingAndMember(offering, member)) {
throw new IllegalArgumentException("이미 참여한 공모엔 참여할 수 없습니다."); // TODO: 예외처리 하기
}
}
}
5 changes: 3 additions & 2 deletions backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VALUES (false, 5, 10000, '2024-07-15 00:00:00', '2024-07-15 00:00:00',
'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png',
'공동구매해요'),
(false, 5, 50000, '2024-07-15 00:00:00', '2024-07-15 00:00:00',
1, '2024-07-21 00:00:00', '뉴진스 굿즈 공동구매 하실 분 참여 부탁', '서울시 영등포구 국제금융로 39', '102동 2802호', 'www.google.com',
1, '2024-08-02 00:00:00', '뉴진스 굿즈 공동구매 하실 분 참여 부탁', '서울시 영등포구 국제금융로 39', '102동 2802호', 'www.google.com',
'https://file.notion.so/f/f/a98aa686-1767-4142-a9a2-f7303fcfa347/650b4cc1-0d39-4cac-9b2a-4db2782e73ec/Untitled.png?id=d002f22a-15bf-486c-b267-1ddc5f6ee3b3&table=block&spaceId=a98aa686-1767-4142-a9a2-f7303fcfa347&expirationTimestamp=1721174400000&signature=gdrQVGGE6z67DvZqeg93wnTB3_Kk3mK8ZxME5jqnWNk&downloadName=Untitled.png',
'뉴진스 굿즈'),
(false, 4, 1000000, '2024-07-01 00:00:00', '2024-07-01 00:00:00',
Expand Down Expand Up @@ -50,4 +50,5 @@ VALUES (false, 5, 10000, '2024-07-15 00:00:00', '2024-07-15 00:00:00',

INSERT INTO OFFERING_MEMBER (OFFERING_ID, MEMBER_ID, ROLE, CREATED_AT, UPDATED_AT)
VALUES (1, 1, 'PROPOSER', '2024-07-15 00:00:00', '2024-07-15 00:00:00'),
(1, 2, 'PARTICIPANT', '2024-07-15 00:00:00', '2024-07-15 00:00:00');
(1, 2, 'PARTICIPANT', '2024-07-15 00:00:00', '2024-07-15 00:00:00'),
(2, 1, 'PROPOSER', '2024-07-15 00:00:00', '2024-07-15 00:00:00');

0 comments on commit e548a1a

Please sign in to comment.