From 5dc40161c4d2da5409decc019df991c27c5374c9 Mon Sep 17 00:00:00 2001 From: hseong3243 Date: Fri, 16 Aug 2024 12:11:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20?= =?UTF-8?q?=EB=82=A8=EC=9D=80=20=EC=88=9C=EB=B2=88=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `WaitingManager`에 남은 순번 조회를 위한 추상 메서드를 정의함. --- .../domain/waiting/WaitingController.java | 29 +++++++++++++++++++ .../manager/DefaultWaitingManager.java | 5 ++++ .../waiting/manager/WaitingManager.java | 9 ++++++ .../waiting/manager/RedisWaitingManager.java | 5 ++++ 4 files changed, 48 insertions(+) create mode 100644 src/main/java/com/thirdparty/ticketing/domain/waiting/WaitingController.java diff --git a/src/main/java/com/thirdparty/ticketing/domain/waiting/WaitingController.java b/src/main/java/com/thirdparty/ticketing/domain/waiting/WaitingController.java new file mode 100644 index 00000000..bc4437f4 --- /dev/null +++ b/src/main/java/com/thirdparty/ticketing/domain/waiting/WaitingController.java @@ -0,0 +1,29 @@ +package com.thirdparty.ticketing.domain.waiting; + +import java.util.Map; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.thirdparty.ticketing.domain.common.LoginMember; +import com.thirdparty.ticketing.domain.waiting.manager.WaitingManager; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api") +public class WaitingController { + + private final WaitingManager waitingManager; + + @GetMapping("/performances/{performanceId}/wait") + public ResponseEntity> getCounts( + @LoginMember String email, @PathVariable("performanceId") Long performanceId) { + long remainingCount = waitingManager.getRemainingCount(email, performanceId); + return ResponseEntity.ok(Map.of("remainingCount", remainingCount)); + } +} diff --git a/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/DefaultWaitingManager.java b/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/DefaultWaitingManager.java index 1dcd8612..4a516e86 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/DefaultWaitingManager.java +++ b/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/DefaultWaitingManager.java @@ -25,6 +25,11 @@ protected long countManagedMember(WaitingMember waitingMember) { return map.get(performanceId); } + @Override + public long getRemainingCount(String email, Long performanceId) { + return 0; + } + public void moveWaitingMemberToRunningRoom(long performanceId, long count) { List waitingMembers = waitingRoom.pollWaitingMembers(performanceId, count); long maxCount = 0L; diff --git a/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/WaitingManager.java b/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/WaitingManager.java index 072ffa50..bbaff374 100644 --- a/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/WaitingManager.java +++ b/src/main/java/com/thirdparty/ticketing/domain/waiting/manager/WaitingManager.java @@ -27,4 +27,13 @@ public long enterWaitingRoom(WaitingMember waitingMember) { } protected abstract long countManagedMember(WaitingMember waitingMember); + + /** + * 사용자의 남은 순번을 조회한다. 남은 순번이 1이하인 경우 이벤트를 발행한다. + * + * @param email 사용자의 이메일 + * @param performanceId 공연 대기 정보 조회를 위한 공연 ID + * @return 사용자의 남은 순번 + */ + public abstract long getRemainingCount(String email, Long performanceId); } diff --git a/src/main/java/com/thirdparty/ticketing/global/waiting/manager/RedisWaitingManager.java b/src/main/java/com/thirdparty/ticketing/global/waiting/manager/RedisWaitingManager.java index 81fc3409..8adf95e8 100644 --- a/src/main/java/com/thirdparty/ticketing/global/waiting/manager/RedisWaitingManager.java +++ b/src/main/java/com/thirdparty/ticketing/global/waiting/manager/RedisWaitingManager.java @@ -27,6 +27,11 @@ protected long countManagedMember(WaitingMember waitingMember) { return Long.parseLong(managedMemberCounter.get(key)); } + @Override + public long getRemainingCount(String email, Long performanceId) { + return 0; + } + private String getPerformanceManagedMemberCounterKey(WaitingMember waitingMember) { return MANAGED_MEMBER_COUNTER_KEY + waitingMember.getPerformanceId(); }