-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Store): 주점 정렬 로직 구현 #148
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
The head ref may contain hidden characters: "feature/#147-store\uB300\uAE30\uC778\uC6D0\uC21C\uC815\uB82C"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.nowait.applicationuser.store.dto; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @Schema(description = "주점 대기 현황 정보 DTO") | ||
| public class StoreWaitingInfo { | ||
| @Schema(description = "주점 ID", example = "1") | ||
| private String storeId; | ||
|
|
||
| @Schema(description = "주점명", example = "노웨이팅 치킨") | ||
| private String storeName; | ||
|
|
||
| @Schema(description = "대기 인원 수", example = "12") | ||
| private Long waitingCount; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,10 +2,12 @@ | |||||||||||||||||||
|
|
||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import org.springframework.data.domain.Pageable; | ||||||||||||||||||||
| import org.springframework.data.domain.Slice; | ||||||||||||||||||||
| import org.springframework.data.redis.core.StringRedisTemplate; | ||||||||||||||||||||
| import org.springframework.stereotype.Service; | ||||||||||||||||||||
| import org.springframework.transaction.annotation.Transactional; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -14,6 +16,7 @@ | |||||||||||||||||||
| import com.nowait.applicationuser.store.dto.StorePageReadDto; | ||||||||||||||||||||
| import com.nowait.applicationuser.store.dto.StoreReadDto; | ||||||||||||||||||||
| import com.nowait.applicationuser.store.dto.StoreReadResponse; | ||||||||||||||||||||
| import com.nowait.applicationuser.store.dto.StoreWaitingInfo; | ||||||||||||||||||||
| import com.nowait.domaincorerdb.department.entity.Department; | ||||||||||||||||||||
| import com.nowait.domaincorerdb.department.repository.DepartmentRepository; | ||||||||||||||||||||
| import com.nowait.domaincorerdb.store.entity.Store; | ||||||||||||||||||||
|
|
@@ -32,6 +35,7 @@ public class StoreServiceImpl implements StoreService { | |||||||||||||||||||
| private final StoreRepository storeRepository; | ||||||||||||||||||||
| private final StoreImageRepository storeImageRepository; | ||||||||||||||||||||
| private final DepartmentRepository departmentRepository; | ||||||||||||||||||||
| private final StringRedisTemplate redisTemplate; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @Override | ||||||||||||||||||||
|
|
@@ -188,4 +192,30 @@ public List<StorePageReadDto> searchStoresByName(String name) { | |||||||||||||||||||
| }) | ||||||||||||||||||||
| .toList(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // 주점 대기 리스트 반환 (많은 순/적은 순) | ||||||||||||||||||||
| @Transactional(readOnly = true) | ||||||||||||||||||||
| public List<StoreWaitingInfo> getStoresByWaitingCount(boolean desc) { | ||||||||||||||||||||
| // 1. 모든 waiting:{storeId} key 조회 (패턴 탐색) | ||||||||||||||||||||
| Set<String> keys = redisTemplate.keys("waiting:*"); | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redis KEYS 명령어 사용에 대한 성능 우려사항이 있습니다. Redis KEYS 명령어는 모든 키를 스캔하므로 운영 환경에서 성능 문제를 일으킬 수 있습니다. SCAN 명령어를 사용하거나, 별도의 인덱스 구조를 고려해보세요: -Set<String> keys = redisTemplate.keys("waiting:*");
+// SCAN을 사용한 개선 방안
+Set<String> keys = new HashSet<>();
+ScanOptions options = ScanOptions.scanOptions().match("waiting:*").build();
+try (Cursor<String> cursor = redisTemplate.scan(options)) {
+ cursor.forEachRemaining(keys::add);
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| if (keys == null) return List.of(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| List<StoreWaitingInfo> result = keys.stream() | ||||||||||||||||||||
| .filter(key -> key.startsWith("waiting:") && !key.startsWith("waiting:party:")) | ||||||||||||||||||||
| .filter(key -> "zset".equals(redisTemplate.type(key).code())) | ||||||||||||||||||||
| .map(key -> { | ||||||||||||||||||||
| Long count = redisTemplate.opsForZSet().zCard(key); | ||||||||||||||||||||
| String storeId = key.replace("waiting:", ""); | ||||||||||||||||||||
| String storeName = storeRepository.findById(Long.valueOf(storeId)) | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Long 파싱에서 예외 처리가 누락되었습니다. storeId를 Long으로 파싱할 때 NumberFormatException이 발생할 수 있습니다. 예외 처리를 추가하세요: -String storeName = storeRepository.findById(Long.valueOf(storeId))
+String storeName;
+try {
+ storeName = storeRepository.findById(Long.valueOf(storeId))
+ .map(Store::getName)
+ .orElse("UNKNOWN");
+} catch (NumberFormatException e) {
+ storeName = "INVALID_STORE_ID";
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| .map(Store::getName) | ||||||||||||||||||||
| .orElse("UNKNOWN"); | ||||||||||||||||||||
| return new StoreWaitingInfo(storeId, storeName, count != null ? count : 0); | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| .sorted((a, b) -> desc ? | ||||||||||||||||||||
| b.getWaitingCount().compareTo(a.getWaitingCount()) : | ||||||||||||||||||||
| a.getWaitingCount().compareTo(b.getWaitingCount())) | ||||||||||||||||||||
| .toList(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return result; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
storeId 타입 일관성을 확인하세요.
다른 부분에서 storeId가 Long 타입으로 사용되는데, 여기서는 String으로 정의되어 있습니다. 타입 일관성을 위해 Long 타입 사용을 고려해보세요.
다음 스크립트로 storeId 타입 사용 패턴을 확인해보겠습니다:
🏁 Script executed:
Length of output: 143956
🏁 Script executed:
#!/bin/bash cat nowait-app-user-api/src/main/java/com/nowait/applicationuser/store/dto/StoreWaitingInfo.javaLength of output: 586
StoreWaitingInfo DTO의 storeId를 Long 타입으로 변경하세요.
일관된 타입 사용을 위해 아래를 수정해주세요:
• nowait-app-user-api/src/main/java/com/nowait/applicationuser/store/dto/StoreWaitingInfo.java
• 서비스 구현부(nowait-app-user-api/src/main/java/com/nowait/applicationuser/store/service/StoreServiceImpl.java)
• key에서 추출한 storeId를 String이 아닌 Long으로 파싱
•
new StoreWaitingInfo(storeId, …)호출부의 첫 번째 인자도 Long으로 변경이렇게 하면 전체 코드베이스에서 storeId가 Long으로 통일되어 의도치 않은 형 변환 오류를 방지할 수 있습니다.
📝 Committable suggestion
🤖 Prompt for AI Agents