Skip to content

Commit

Permalink
Merge pull request #95 from Team-Going/feature/94
Browse files Browse the repository at this point in the history
[feat] 여행 입장 최대 인원 제한 검증 로직 추가
  • Loading branch information
SunwoongH authored Jan 16, 2024
2 parents 33decb5 + 72e9fff commit 79d8323
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions doorip-api/src/main/java/org/doorip/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public abstract class Constants {
public static final int MIN_STYLE_RATE = 0;
public static final int MAX_STYLE_RATE = 100;
public static final int PROPENSITY_WEIGHT = 25;
public static final int MAX_PARTICIPANT_COUNT = 6;
}
6 changes: 5 additions & 1 deletion doorip-api/src/main/java/org/doorip/trip/api/TripApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ResponseEntity<BaseResponse<?>> getTrips(@Parameter(hidden = true)
@RequestParam final String progress);

@Operation(
summary = "초대 코드 검증 API",
summary = "초대코드 검증 API",
responses = {
@ApiResponse(
responseCode = "200",
Expand All @@ -114,6 +114,10 @@ ResponseEntity<BaseResponse<?>> getTrips(@Parameter(hidden = true)
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "400",
description = "여행에 입장할 수 있는 최대 인원은 6명입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 형식이 올바르지 않습니다. Bearer 타입을 확인해 주세요.",
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ErrorMessage {
INVALID_ALLOCATOR_COUNT(HttpStatus.BAD_REQUEST, "e4003", "여행 TODO를 생성하기 위해 최소 1명 이상의 배정자가 필요합니다."),
INVALID_DATE_TYPE(HttpStatus.BAD_REQUEST, "e4004", "유효하지 않은 날짜 타입입니다."),
INVALID_RESULT_TYPE(HttpStatus.BAD_REQUEST, "e4004", "유효하지 않은 성향 입력 값입니다."),
INVALID_PARTICIPANT_COUNT(HttpStatus.BAD_REQUEST, "e4005", "여행에 입장할 수 있는 최대 인원은 6명입니다."),

/**
* 401 Unauthorized
Expand Down

0 comments on commit 79d8323

Please sign in to comment.