Skip to content
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 @@ -229,7 +229,7 @@ public ErrorResponse duplicateReservationException(DuplicateReservationException
public ErrorResponse alreadyWaitingException(AlreadyDeletedWaitingException e, WebRequest request) {
alarm(e, request);
log.error("alreadyWaitingException", e);
return new ErrorResponse(e.getMessage(), DUPLICATE_RESERVATION.getCode());
return new ErrorResponse(e.getMessage(), ALREADY_DELETED_RESERVATION.getCode());
}

@ResponseStatus(BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public class WaitingService {
@Transactional
public RegisterWaitingResponse registerWaiting(CustomOAuth2User oAuth2User, String publicCode, RegisterWaitingRequest waitingRequest, HttpServletRequest httpServletRequest) {

String idempotentKey = httpServletRequest.getHeader("Idempotency-Key");

// TODO 멱등성 검증 로직 점검 필요
Optional<WaitingIdempotencyValue> existingIdempotencyValue = waitingIdempotencyRepository.findByKey(idempotentKey);
if (existingIdempotencyValue.isPresent()) {
log.info("Existing idempotency key found: {}", idempotentKey);
return existingIdempotencyValue.get().getResponse();
}

// TODO 유저 및 주점 존재 검증은 공통으로 많이 쓰이니 AOP로 빼는게 좋을 듯
Store store = storeRepository.findByPublicCodeAndDeletedFalse(publicCode)
.orElseThrow(StoreNotFoundException::new);
Expand All @@ -65,18 +74,10 @@ public RegisterWaitingResponse registerWaiting(CustomOAuth2User oAuth2User, Stri
Long storeId = store.getStoreId();
LocalDateTime timestamp = LocalDateTime.now();
String waitingNumber = generateWaitingNumber(storeId, timestamp);
String idempotentKey = httpServletRequest.getHeader("Idempotency-Key");

// 멱등키 검증 - 이미 동일한 멱등키로 등록된 웨이팅이 있는지 확인
// waitingRedisRepository.idempotentKeyKeyExists(idempotentKey, ReservationStatus.WAITING.name());

// TODO 멱등성 검증 로직 점검 필요
Optional<WaitingIdempotencyValue> existingIdempotencyValue = waitingIdempotencyRepository.findByKey(idempotentKey);
if (existingIdempotencyValue.isPresent()) {
log.info("Existing idempotency key found: {}", idempotentKey);
return existingIdempotencyValue.get().getResponse();
}


// 일일 가능 웨이팅 최대 개수 초과 검증
// TODO race condition 발생 가능성 점검 필요
Expand Down