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(); }