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

GTB-76 [feat] 웨이팅 신청 방식 변경 #89

Merged
merged 8 commits into from
Sep 24, 2024
Merged

GTB-76 [feat] 웨이팅 신청 방식 변경 #89

merged 8 commits into from
Sep 24, 2024

Conversation

jwnnoh
Copy link
Member

@jwnnoh jwnnoh commented Sep 24, 2024

1. 무슨 이유로 코드를 변경했나요?

  • 정책 변경에 따른 웨이팅 신청 방식을 변경하기 위함입니다.

AS-IS

  • 웨이팅 객체 생성 시 headCount 에 인원수 값을 입력하여 진행합니다.

TO-BE

  • 열거형 상수로 구분되는 테이블 방식을 선택하여 웨이팅 객체가 생성됩니다.
public enum Table {
    BASIC("4인 테이블 (1~5인)"),
    PARTY("8인 테이블 `(5~8인)");

    private final String nameKo;
}

2. 어떤 위험이나 장애를 발견했나요?

  • 사용자가 웨이팅 내역을 조회 시, 취소된 웨이팅에서는 Seating 객체를 불러오지 못해 의도치 않은 NPE가 발생하는 것을 파악,
    수정하였습니다.

3. 관련 스크린샷을 첨부해주세요.

원격 웨이팅

원격 웨이팅

주점 관리자 대기열 조회 시

어드민 주점 대기열 조회

사용자 웨이팅 내역 조회 오류 수정

유저 웨이팅 내역 조회

4. 완료 사항

  • 웨이팅 방식 수정
    • 테이블을 BASIC, PARTY로 설정하여 웨이팅을 신청하도록 변경하였습니다.

이슈 번호

close #88


5. 추가 사항

  • 웨이팅 내역 조회시 취소된 웨이팅을 가져올 때 의도치 않은 오류가 생기는 부분을 수정하였습니다.

    🤔 Seating 유무에 따른 로직을 어떻게 구성해야할까?

    고민했던 방식은 총 2가지였습니다.

    Optional을 사용한 로직

 return waitings.stream()
       .map(waiting -> seatingRepository.findByWaiting(waiting)
               .map(seating -> WaitingHistoryResponse.of(waiting, seating))
               .orElseGet(() -> WaitingHistoryResponse.of(waiting, null)))
       .toList();
  • 해당 방식은 Seating 유무에 따라 분기점을 두고 있습니다. (orElseGet)
  • 간결하지만, 직접적 가독성은 떨어진다는 단점이 있습니다.
  • 만약 Seating이 있어야 할 Waiting에 Seating이 없을 경우, 오류를 찾아낼 수 없다는 단점이 마찬가지로 존재합니다.

if-early return을 사용한 로직

return waitings.stream()
      .map(waiting -> {
          if (waiting.getWaitingStatus() == Status.ENTERED) {
              Seating seating = seatingRepository.findByWaiting(waiting)
                      .orElseThrow(SeatingNotFoundException::new);
              return WaitingHistoryResponse.of(waiting, seating);
          }
          return WaitingHistoryResponse.of(waiting, null);
      })
      .toList();
  • 웨이팅의 상태에 따른 분기점을 두고 있기에, 가독성 측면에서 무척 뛰어나며, 의도한 바를 잘 드러냅니다.
  • 반면 코드의 길이에 따른 약간의 장황함이 수반되기도 합니다.

결론

  • 해당 오류는 입장한 웨이팅과 취소된 웨이팅을 적절히 구분하지 못하고 하나의 로직으로 처리하려다가 발생한 문제였습니다.

  • 따라서 Seating을 기준으로 로직을 분리하는 것은 옿지 않다고 판단하였고, @hoonyworld 님도 해당 부분을 지적해주셨습니다.

  • 따라서 기존 의도대로 웨이팅의 상태(입장함 | 취소함)를 기반으로 분기점을 생성하는 것이 낫다고 판단, 그렇게 적용하였습니다.

  • 정책 변경에 따른 주점당 최대 웨이팅 수 적용

    • 설정한 웨이팅 대기열 수에 도달하면 자동으로 주점의 상태가 대기 마감으로 변경됩니다.

@jwnnoh jwnnoh added ✨ feature 새로운 기능 ♻️ refactor 코드 리팩토링 🚑 hotfix 긴급한 코드 수정 labels Sep 24, 2024
@jwnnoh jwnnoh self-assigned this Sep 24, 2024
@jwnnoh jwnnoh requested review from rootTiket and yechan-kim and removed request for rootTiket September 24, 2024 11:28
Copy link
Contributor

@rootTiket rootTiket left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!! 최대 주점 예약인원을 파악 할 때 동시성 문제가 발생 할 수 있는 부분도 잘 관리된 것 같아요 :) 👍

Copy link
Contributor

@yechan-kim yechan-kim left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 전반적으로 코드가 잘 구현이 되어있는 것 같습니다!!!
코드를 보다가 궁금한 점을 달아 두었는데, 한번 읽어보시고 의견 부탁드립니다!

Comment on lines +121 to 125
private void checkMaxWaitingCount() {
if (this.waitingCount >= MAX_WAITING_COUNT) {
this.waitingStatus = false;
}
}
Copy link
Contributor

@yechan-kim yechan-kim Sep 24, 2024

Choose a reason for hiding this comment

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

웨이팅을 30개로 제한을 두는 부분을 추가하신 이유가 있으실까요? 정책이 변경된 건가요?

Copy link
Member Author

Choose a reason for hiding this comment

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

그렇습니다! 해당 부분 노션에 정리되어 있으니 확인 부탁드립니다 😄

tableId -> seatingId
tableNum -> seatingNum
@jwnnoh jwnnoh merged commit 1253953 into develop Sep 24, 2024
@jwnnoh jwnnoh deleted the GTB-76 branch September 24, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature 새로운 기능 🚑 hotfix 긴급한 코드 수정 ♻️ refactor 코드 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GTB-76 [feat] 웨이팅 신청 방식 변경
3 participants