Skip to content

Commit 9baf0b9

Browse files
feat: 대기열 도메인 나를 포함한 상위인원 모두 입장처리하는 테스트 API 추가
1 parent b3eb377 commit 9baf0b9

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

backend/src/main/java/com/back/api/queue/controller/QueueEntryApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,18 @@ ApiResponse<ProcessEntriesResponse> processUntilMe(
7575
@Parameter(description = "이벤트 ID", example = "1")
7676
@PathVariable Long eventId
7777
);
78+
79+
@Operation(
80+
summary = "[테스트용] 나를 포함한 앞 사용자 모두 입장 처리",
81+
description = "나를 포함하여 내 앞에 있는 모든 사용자들을 입장 처리합니다."
82+
)
83+
@ApiErrorCode({
84+
"NOT_FOUND_QUEUE_ENTRY",
85+
"NOT_WAITING_STATUS",
86+
"NOT_INVALID_COUNT"
87+
})
88+
ApiResponse<ProcessEntriesResponse> processIncludingMe(
89+
@Parameter(description = "이벤트 ID", example = "1")
90+
@PathVariable Long eventId
91+
);
7892
}

backend/src/main/java/com/back/api/queue/controller/QueueEntryController.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ public ApiResponse<ProcessEntriesResponse> processUntilMe(
8181
return ApiResponse.ok("내 앞 사용들이 모두 입장 처리가 완료되었습니다.", response);
8282
}
8383

84+
@Override
85+
@PostMapping("/{eventId}/process-include-me")
86+
public ApiResponse<ProcessEntriesResponse> processIncludingMe(
87+
@PathVariable Long eventId
88+
) {
89+
Long userId = httpRequestContext.getUserId();
90+
91+
ProcessEntriesResponse response = queueEntryProcessService.processTopEntriesIncludingMeForTest(
92+
eventId,
93+
userId
94+
);
95+
96+
return ApiResponse.ok("나를 포함한 내 앞 사용들이 모두 입장 처리가 완료되었습니다.", response);
97+
}
98+
8499
}

backend/src/main/java/com/back/api/queue/service/QueueEntryProcessService.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,48 @@ public ProcessEntriesResponse processTopEntriesUntilMeForTest(Long eventId, Long
236236
return ProcessEntriesResponse.from(eventId, userIds.size(), remainingCount);
237237
}
238238

239+
/* ==================== 테스트용 내 앞에 사람 + 나까지 모두 입장 처리 ==================== */
240+
@Transactional
241+
public ProcessEntriesResponse processTopEntriesIncludingMeForTest(Long eventId, Long userId) {
242+
243+
QueueEntry myEntry = queueEntryRepository.findByEvent_IdAndUser_Id(eventId, userId)
244+
.orElseThrow(() -> new ErrorException(QueueEntryErrorCode.NOT_FOUND_QUEUE_ENTRY));
245+
246+
if (myEntry.getQueueEntryStatus() != QueueEntryStatus.WAITING) {
247+
throw new ErrorException(QueueEntryErrorCode.NOT_WAITING_STATUS);
248+
}
249+
250+
Long myRank = queueEntryRedisRepository.getMyRankInWaitingQueue(eventId, userId);
251+
252+
if (myRank == null) {
253+
throw new ErrorException(QueueEntryErrorCode.NOT_FOUND_QUEUE_ENTRY);
254+
}
255+
256+
// 나를 포함한 입장 처리 (나의 순위만큼 처리)
257+
int countToProcess = myRank.intValue();
258+
259+
Set<Object> topWaitingUsers = queueEntryRedisRepository.getTopWaitingUsers(eventId, countToProcess);
260+
261+
if (topWaitingUsers.isEmpty()) {
262+
throw new ErrorException(QueueEntryErrorCode.NOT_INVALID_COUNT);
263+
}
264+
265+
List<Long> userIds = new ArrayList<>();
266+
for (Object userIdObj : topWaitingUsers) {
267+
userIds.add(Long.parseLong(userIdObj.toString()));
268+
}
269+
270+
if (userIds.isEmpty()) {
271+
return ProcessEntriesResponse.from(eventId, 0,
272+
queueEntryRedisRepository.getTotalWaitingCount(eventId));
273+
}
274+
275+
processBatchEntry(eventId, userIds);
276+
publishWaitingUpdateEvents(eventId);
277+
278+
Long remainingCount = queueEntryRedisRepository.getTotalWaitingCount(eventId);
279+
return ProcessEntriesResponse.from(eventId, userIds.size(), remainingCount);
280+
}
239281

240282
/* ==================== 만료 처리 ==================== */
241283

0 commit comments

Comments
 (0)