반응형
목차
✅ 트러블 슈팅
1. 문제 상황
- 예약 시간과 멘토, 멘티 ID가 동일한 경우 중복으로 판단하려고 작성하였으나, 겹치지 않는 시간에도 중복 예약으로 인식되는 문제 발생.
boolean exists =
reservationRepository.existsByMentorIdOrMenteeIdAndReservationStartAtAndReservationEndAt(
requestDto.getMentor(), userId, requestDto.getReservationStartAt(),
requestDto.getReservationEndAt());
if(exists){
throw new BaseException(ErrorCode.DUPLICATED_RESERVATION);
}
boolean existsByMentorIdOrMenteeIdAndReservationStartAtAndReservationEndAt(Long mentorId, Long menteeId, LocalDateTime startAt, LocalDateTime endAt);
2. 원인 분석
- 멘토나 멘티 중 한 명만 일치하면 중복으로 판단함.
3. 해결 방법
- JPQL을 이용하여 조건 정의.
@Query("""
SELECT CASE WHEN COUNT(r) > 0 THEN true ELSE false END FROM Reservation r
WHERE (r.mentor.id = :mentorId OR r.mentee.id = :menteeId)
AND (r.reservationStartAt < :endAt AND r.reservationEndAt > :startAt)""")
boolean existsByMentorOrMenteeAndTime(@Param("mentorId") Long mentorId,
@Param("menteeId") Long menteeId,
@Param("startAt") LocalDateTime startAt,
@Param("endAt") LocalDateTime endAt);
반응형
'스파르타 내일배움캠프 > TIL(Today I learned)' 카테고리의 다른 글
Redisson 분산락 vs Redis 원자 연산 기반 동시성 제어 (2) | 2025.06.12 |
---|---|
fix: 민원 관련 코드 수정 (0) | 2025.06.11 |
동시성 제어 (1) | 2025.06.09 |
페이징 처리 직렬화 관련 이슈 (1) | 2025.06.05 |
최종 프로젝트 6일차 - 트러블 슈팅 (2) | 2025.06.04 |