Skip to content

Commit

Permalink
feat: 여행 참여자 최대 인원 검증 로직 추가 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Jan 16, 2024
1 parent d9b4c5c commit 297bf5b
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public TripCreateResponse createTripAndParticipant(Long userId, TripCreateReques
Trip trip = createTrip(request, code);
createParticipant(request, findUser, trip);
tripRepository.save(trip);

return TripCreateResponse.of(trip);
}

Expand All @@ -53,7 +52,6 @@ public TripEntryResponse entryTrip(Long userId, Long tripId, TripEntryRequest re
Trip findTrip = getTrip(tripId);
validateDuplicateParticipant(findUser, findTrip);
createAndSaveParticipant(request, findUser, findTrip);

return TripEntryResponse.of(findTrip);
}

Expand All @@ -65,9 +63,17 @@ public TripGetResponse getTrips(Long userId, String progress) {

public TripResponse verifyCode(TripVerifyRequest request) {
Trip trip = getTrip(request.code());
List<Participant> participants = trip.getParticipants();
validateParticipantCount(participants);
return TripResponse.of(trip);
}

private void validateParticipantCount(List<Participant> participants) {
if (participants.size() == Constants.MAX_PARTICIPANT_COUNT) {
throw new InvalidValueException(ErrorMessage.INVALID_PARTICIPANT_COUNT);
}
}

private void validateDate(LocalDate startDate, LocalDate endDate) {
if (endDate.isBefore(LocalDate.now()) || endDate.isBefore(startDate)) {
throw new InvalidValueException(ErrorMessage.INVALID_DATE_TYPE);
Expand All @@ -80,7 +86,6 @@ private String createCode() {
String uuid = UUID.randomUUID().toString();
code = uuid.substring(0, 6);
} while (isDuplicateCode(code));

return code;
}

Expand Down

0 comments on commit 297bf5b

Please sign in to comment.