Skip to content

예약 취소 기능 구현#12

Merged
enjoy89 merged 8 commits intomainfrom
feature/reservation-manage
Feb 5, 2026
Merged

예약 취소 기능 구현#12
enjoy89 merged 8 commits intomainfrom
feature/reservation-manage

Conversation

@enjoy89
Copy link
Collaborator

@enjoy89 enjoy89 commented Feb 3, 2026

개요

  • 예약 취소 기능 구현
  • 취소 가능 조건(방문 시각 기준 24시간 이전) 검증 로직 추가
  • 취소 시 예약 상태 변경 및 좌석(capacity) 복구 처리

메인 리뷰어 지정

리뷰 시 참고 사항

  • 라인 수 제한을 지키기 위해, 이번 PR은 예약 취소 기능과 서비스 레이어 단위/통합 테스트까지만 포함했습니다. 컨트롤러 레이어 테스트는 다음 PR로 분리해서 올리겠습니다. 😅
  • 현재 작성한 테스트 구조에 대해 아래 관점에서 리뷰 해주시면 감사하겠습니다.
    • 테스트 범위가 과도하지 않은지, 중복 검증이나 불필요한 코드가 존재하지는 않는지
    • 단위 테스트와 통합 테스트 간 역할 분리가 적절한지
    • 가독성과 유지보수 관점에서 더 단순화할 수 있는 구조가 있는지

작업 시 고민사항

  • 현재 테스트 코드의 유지보수성과 구조에 대해 많은 고민을 하고 있는 상태입니다. 기능을 하나씩 추가하다 보니, 비즈니스 로직 자체보다 “이 검증은 어느 레벨에서 책임지는 게 맞을까?” 라는 고민이 점점 커지고 있습니다.
  • 특히 예약 생성/조회/취소 로직이 서로 영향을 주면서 테스트 준비 코드와 검증 포인트가 자연스럽게 늘어나고 있고, 그 과정에서 단위 테스트와 통합 테스트의 경계가 다소 흐려지고 있는 느낌도 받고 있습니다.
  • 이번 PR에서는 우선 기능의 정확성과 안정성 확보를 목표로 테스트를 작성했지만, 앞으로 기능이 더 추가될 경우 테스트 구조가 계속 증가·변형될 가능성이 있어 지금 시점에서 테스트 구조를 어떻게 가져가는 게 좋은지 방향성에 대한 피드백을 받고 싶습니다.

TODO

  • 예약 취소 기능 컨트롤러 테스트 코드 작성

References

체크리스트

  • PR 제목을 명령형으로 작성했습니다.
  • PR을 연관되는 github issue에 연결했습니다.
  • 리뷰 리퀘스트 전에 셀프 리뷰를 진행했습니다
  • 변경사항에 대한 테스트코드를 추가했습니다. 또는, 테스트 코드가 필요없는 이유가 있습니다.

관련 이슈

- DailySlotCapacity 업데이트 구조에 따른 코드 수정
# Conflicts:
#	src/main/java/com/reservation/tablereservationservice/application/reservation/service/ReservationService.java
#	src/main/java/com/reservation/tablereservationservice/domain/reservation/ReservationRepository.java
#	src/main/java/com/reservation/tablereservationservice/infrastructure/reservation/repository/JpaReservationRepository.java
#	src/main/java/com/reservation/tablereservationservice/presentation/reservation/controller/ReservationController.java
#	src/test/java/com/reservation/tablereservationservice/application/reservation/service/ReservationServiceIntegrationTest.java
#	src/test/java/com/reservation/tablereservationservice/application/reservation/service/ReservationServiceTest.java
- 테스트 기준 날짜를 고정값(2030-01-01)으로 통일
- 단위 테스트에서 식별자(id)를 명시적으로 주입하도록 fixture 정리
- 테스트 간 id 충돌 및 null 문제를 방지하도록 restaurant / slot / reservation fixture 보완
- 예약 취소 로직 추가에 따라 예약 목록 조회 테스트를 기간/상태 필터링 케이스로 확장
@enjoy89 enjoy89 requested a review from blue000927 February 3, 2026 12:15
@enjoy89 enjoy89 self-assigned this Feb 3, 2026
@enjoy89 enjoy89 added the feature label Feb 3, 2026
Copy link

@blue000927 blue000927 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로덕션 코드는 어느정도 감을 잡으신 것 같아서 좋네요!

테스트 코드의 경우 당연히 많이 짜면 많이 짤수록 좋지만 어느정도 가성비를 따진다면, 서비스 레이어는 모킹 대신 통합 테스트 정도로만 짜도 괜찮다고 생각해요 :)
TestFixture로 분리, 도메인 단위 테스트, 서비스 통합 테스트, 컨트롤러 통합 테스트 이런 셈이죠!

해당 PR에 컨트롤러 테스트도 그대로 올려주시면 금방 어프로브 가능할듯싶네요.

Comment on lines +248 to +260
private void validateCancelable(Long userId, Reservation reservation) {
if (!reservation.getUserId().equals(userId)) {
throw new ReservationException(ErrorCode.RESERVATION_FORBIDDEN);
}

if (reservation.getStatus() == ReservationStatus.CANCELED) {
throw new ReservationException(ErrorCode.RESERVATION_ALREADY_CANCELED);
}

LocalDateTime cancelDeadline = reservation.getVisitAt().minusHours(24);
if (!LocalDateTime.now().isBefore(cancelDeadline)) {
throw new ReservationException(ErrorCode.RESERVATION_CANCEL_DEADLINE_PASSED);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 로직 모두는 Reservation에서 관리하면 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵, 취소 검증 로직을 Reservation 도메인으로 이동시켰습니다!

- 도메인은 boolean 결과만 반환하고 예외 처리는 서비스에서 담당
- 현재 시점(now)을 서비스에서 한 번만 생성하도록 개선
- 중복되는 서비스 단위 테스트 일부 제거
@enjoy89 enjoy89 merged commit 18cbaf3 into main Feb 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

예약 취소 기능 구현

2 participants