-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9c13de
commit 2664776
Showing
12 changed files
with
147 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/meltingpot/server/domain/entity/party/enums/PartyStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package meltingpot.server.domain.entity.party.enums; | ||
|
||
public enum PartyStatus { | ||
TEMP_SAVED, RECRUIT_SCHEDULED, RECRUIT_OPEN, RECRUIT_CLOSED, RUNNING, DONE, | ||
TEMP_SAVED, CANCELED, RECRUIT_SCHEDULED, RECRUIT_OPEN, RECRUIT_CLOSED, RUNNING, DONE, | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/meltingpot/server/domain/repository/PartyContentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package meltingpot.server.domain.repository; | ||
|
||
import meltingpot.server.domain.entity.party.PartyContent; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PartyContentRepository extends JpaRepository<PartyContent, Long> { | ||
List<PartyContent> findAllByPartyId(int partyId); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/meltingpot/server/domain/repository/PartyParticipantRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package meltingpot.server.domain.repository; | ||
|
||
import meltingpot.server.domain.entity.party.PartyParticipant; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PartyParticipantRepository extends JpaRepository<PartyParticipant, Long> { | ||
List<PartyParticipant> findAllByPartyId(int partyId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/meltingpot/server/party/dto/PartyContentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package meltingpot.server.party.dto; | ||
|
||
import lombok.Builder; | ||
import meltingpot.server.domain.entity.party.PartyContent; | ||
|
||
@Builder | ||
public record PartyContentResponse( | ||
String lang, | ||
String content | ||
) { | ||
public static PartyContentResponse of(PartyContent partyContent) { | ||
return PartyContentResponse.builder() | ||
.lang(partyContent.getPartyContentLang()) | ||
.content(partyContent.getPartyContent()) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/meltingpot/server/party/dto/PartyParticipantResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package meltingpot.server.party.dto; | ||
|
||
import lombok.Builder; | ||
import meltingpot.server.domain.entity.party.PartyParticipant; | ||
|
||
@Builder | ||
public record PartyParticipantResponse( | ||
String name | ||
) { | ||
public static PartyParticipantResponse of(PartyParticipant partyParticipant) { | ||
return PartyParticipantResponse.builder() | ||
.name(partyParticipant.getAccount().getName()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 50 additions & 2 deletions
52
src/main/java/meltingpot/server/party/service/PartyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,67 @@ | ||
package meltingpot.server.party.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import meltingpot.server.domain.entity.Account; | ||
import meltingpot.server.domain.entity.party.PartyParticipant; | ||
import meltingpot.server.domain.entity.party.enums.ParticipantStatus; | ||
import meltingpot.server.domain.entity.party.enums.PartyStatus; | ||
import meltingpot.server.domain.repository.PartyParticipantRepository; | ||
import meltingpot.server.domain.repository.PartyRepository; | ||
import meltingpot.server.party.dto.PartyResponse; | ||
import meltingpot.server.util.ResponseCode; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import meltingpot.server.domain.entity.party.Party; | ||
|
||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class PartyService { | ||
private final PartyRepository partyRepository; | ||
private final PartyParticipantRepository partyParticipantRepository; | ||
|
||
@Transactional | ||
public PartyResponse getParty(int partyId, Account user) { | ||
Party party = partyRepository.findById(partyId).orElseThrow(); | ||
PartyStatus partyStatus = party.getPartyStatus(); | ||
|
||
boolean isPartyOwner = party.getAccount().equals(user); | ||
|
||
if ((!isPartyOwner && partyStatus == PartyStatus.TEMP_SAVED) || partyStatus == PartyStatus.CANCELED) { | ||
throw new NoSuchElementException(); | ||
} | ||
|
||
return PartyResponse.of(party); | ||
} | ||
|
||
@Transactional | ||
public PartyResponse getParty(Long partyId) { | ||
return partyRepository.findById(partyId).map(PartyResponse::of).orElseThrow(); | ||
public ResponseCode joinParty(int partyId, Account user) { | ||
Party party = partyRepository.findById(partyId).orElseThrow(); | ||
PartyStatus partyStatus = party.getPartyStatus(); | ||
|
||
if (partyStatus != PartyStatus.RECRUIT_OPEN) { | ||
return ResponseCode.PARTY_NOT_OPEN; | ||
} | ||
|
||
List<PartyParticipant> partyParticipants = party.getPartyParticipants().stream().filter((participant) -> participant.getParticipantStatus() != ParticipantStatus.CANCELED).toList(); | ||
if (partyParticipants.stream().anyMatch((participant) -> participant.getParticipantStatus() != ParticipantStatus.CANCELED && participant.getAccount().equals(user))) { | ||
return ResponseCode.PARTY_ALREADY_JOINED; | ||
} | ||
|
||
if (partyParticipants.size() >= party.getPartyMaxParticipant()) { | ||
return ResponseCode.PARTY_FULL; | ||
} | ||
|
||
PartyParticipant partyParticipant = PartyParticipant.builder() | ||
.party(party) | ||
.account(user) | ||
.participantStatus(ParticipantStatus.APPROVED) | ||
.build(); | ||
partyParticipantRepository.save(partyParticipant); | ||
|
||
return ResponseCode.PARTY_JOIN_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters