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] #162 - 공연 삭제 로직 변경 #163

Merged
merged 9 commits into from
Aug 6, 2024
Merged

[fix] #162 - 공연 삭제 로직 변경 #163

merged 9 commits into from
Aug 6, 2024

Conversation

hoonyworld
Copy link
Member

@hoonyworld hoonyworld commented Aug 5, 2024

Related issue 🛠

Work Description ✏️

공연 삭제 로직 - 기존

boolean hasBookings = bookingRepository.existsBySchedulePerformanceId(performanceId);
  • Booking과 Schedule을 조인하여, Schedule이 참조하는 Performance의 ID가 주어진 performanceId와 일치하는지를 검사합니다.

공연 삭제 로직 - 변경

@Query("SELECT COUNT(b) > 0 FROM Booking b WHERE b.schedule.id IN :scheduleIds")
boolean existsByScheduleIdIn(@Param("scheduleIds") List<Long> scheduleIds);
  • Booking 테이블에서 주어진 scheduleIds 리스트 중 하나라도 존재하는지를 확인합니다.

변경 사유

  • 변경 전 로직도 공연 삭제가 가능한 로직이라고 판단되고, 실제로 로컬에서 돌렸을 때 공연 삭제가 잘 되었습니다.
  • 다만 Client 측에서 테스트를 했을 때 공연 삭제가 안되는 문제가 발생했고, 자동으로 생성된 쿼리가 예기치 못한 문제를 일으킬 수도 있다고 생각이 들었습니다.
  • 따라서 JPQL을 사용해 명시적으로 쿼리를 작성하므로서 쿼리의 명확성을 높이고, performanceId 대신 List scheduleIds를 줘 불필요한 조인을 하지 않고 삭제가 가능하도록 변경했습니다.

promotion 양방향 매핑

  • promotion은 performanceId를 외래키로 가지며, performance가 삭제되면 이론상 해당 performance의 id를 외래키로 가지고 있는 promotion의 튜플을 삭제하도록 구현했어야 했습니다.
  • 하지만 구현이 안된 것을 확인하였고, @onDelete로 단방향 방식을 적용하고 싶었으나 ddl-auto를 create 옵션으로 해서 테이블을 초기화 시켜야 했기에 기존 데이터를 백업하고 재배포 하는 방식보다 양방향 매핑을 하는 것이 시간 리소스가 덜 할거라고 판단되어서 양방향 매핑으로 진행을 하게 되었습니다.

불필요한 pathVariable 어노테이션 제거

  • 예매자 삭제시 performanceId를 requestBody로 받고 있는데, performanceId가 pathVariable로도 받도록 구현이 되어있었습니다.
  • 따라서 해당 부분을 삭제하고 api 경로를 /api/tickets/{performanceId} -> /api/tickets로 수정하였습니다.

Trouble Shooting ⚽️

Related ScreenShot 📷

해당 공연의 메이커가 아닌 경우 수정 페이지 공연 조회 불가

image

예매자가 하나도 없는 경우 isBookerExist : false 확인

image

1회차 예매 진행 -> isBookerExist : true 확인 따라서 해당 jpql로 지어진 메서드가 잘 작동되는지 확인 완료

image

1회차 예매 진행한 공연의 경우 삭제가 되지 않는거 확인 완료

image

예매가 없는 공연의 경우 삭제가 되는거 확인 완료

image

해당 공연의 메이커가 아니면 예매자를 삭제할 수 없도록 변경

image

정상적으로 예매자 삭제 완료 및 DB에서도 확인 완료

image

다시 11번째 공연을 조회하면 isBookerExist가 false로 변경된거 확인 가능

image

공연 삭제 가능 및 cascade로 performanceId=11을 가지고 있는 테이블(schedule, promotion, cast, staff) 튜플 삭제 확인

image

Uncompleted Tasks 😅

To Reviewers 📢

  • 불필요한 pathVariable을 삭제하고 예매자 삭제 api의 경로명을 /api/tickets/{performanceId} -> /api/tickets로 수정하였습니다.
  • 주석을 달아 놓았지만 TicketController에서 예매자 입금여부 수정 및 웹발신 API도 마찬가지로 /api/tickets/{performanceId} -> /api/tickets로 수정해야 합니다. 이 부분은 혜린님꼐서 잘 아시는 코드라 수정하지 않고 남겨두었으니 수정 부탁드립니다!

@hoonyworld hoonyworld self-assigned this Aug 5, 2024
@hoonyworld hoonyworld linked an issue Aug 5, 2024 that may be closed by this pull request
2 tasks
@@ -32,5 +32,6 @@ Optional<Booking> findFirstByBookerNameAndBookerPhoneNumberAndBirthDateAndPasswo

List<Booking> findByUsersId(Long userId);

boolean existsBySchedulePerformanceId(Long performanceId);
@Query("SELECT COUNT(b) > 0 FROM Booking b WHERE b.schedule.id IN :scheduleIds")
boolean existsByScheduleIdIn(@Param("scheduleIds") List<Long> scheduleIds);
Copy link
Collaborator

Choose a reason for hiding this comment

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

boolean 이름에 In 붙이신 의도가 무엇일까요? 혹시 오타인지 확인 부탁드립니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

이름은 IN 연산자를 사용하는 SQL 쿼리의 의미를 나타내기 위해 사용했습니다!

Copy link
Collaborator

@hyerinhwang-sailin hyerinhwang-sailin left a comment

Choose a reason for hiding this comment

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

scheduleId로 조회해서 공연 삭제하는 로직, promotion 양방향 매핑으로 performance 삭제 시 promotion도 함께 삭제되도록 구현하신 것 모두 좋습니다!
예매자 입금여부 수정 api도 삭제 api와 동일하게 경로 수정하도록 하겠습니다!

@hoonyworld hoonyworld merged commit 405880a into develop Aug 6, 2024
1 check passed
@hoonyworld hoonyworld deleted the bug/#162 branch August 7, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] 공연 삭제가 안되는 이슈
2 participants