Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 여행 입장 최대 인원 검증 로직 오류 수정 #110

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public TripEntryResponse entryTrip(Long userId, Long tripId, TripEntryRequest re
User findUser = getUser(userId);
Trip findTrip = getTrip(tripId);
validateDuplicateParticipant(findUser, findTrip);
validateParticipantCount(findTrip.getParticipants());
createAndSaveParticipant(request, findUser, findTrip);
return TripEntryResponse.of(findTrip);
}
Expand All @@ -63,17 +64,9 @@ 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 Down Expand Up @@ -128,6 +121,12 @@ private void validateDuplicateParticipant(User user, Trip trip) {
}
}

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

private void createAndSaveParticipant(TripEntryRequest request, User user, Trip trip) {
Participant.createParticipant(Role.PARTICIPATION, request.styleA(),
request.styleB(), request.styleC(), request.styleD(), request.styleE(), user, trip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum ErrorMessage {
*/
CONFLICT(HttpStatus.CONFLICT, "e4090", "이미 존재하는 리소스입니다."),
DUPLICATE_USER(HttpStatus.CONFLICT, "e4091", "이미 존재하는 회원입니다."),
DUPLICATE_PARTICIPANT(HttpStatus.CONFLICT, "e4092", "이미 존재하는 참가자입니다."),
DUPLICATE_PARTICIPANT(HttpStatus.CONFLICT, "e4092", "이미 존재하는 참여자입니다."),

/**
* 500 Internal Server Error
Expand Down