Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ReservationController {
@GetMapping("/admin/{storeId}/waiting/users")
@Operation(summary = "주점별 전체 대기/호출중 리스트 조회", description = "주점에 대한 대기 리스트 조회(WAITING,CALLING)")
@ApiResponse(responseCode = "200", description = "주점별 전체 대기 리스트 조회")
public ResponseEntity<List<WaitingUserResponse>> getWaitingUsersWithScore(@PathVariable Long storeId) {
public ResponseEntity<?> getWaitingUsersWithScore(@PathVariable Long storeId) {
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

반환 타입을 구체적으로 유지하는 것을 권장합니다.

ResponseEntity<?>로 변경하면 타입 안전성이 감소하고 API 계약이 불분명해집니다. 메서드가 실제로는 List<WaitingUserResponse>를 반환하므로, 원래의 구체적인 타입 ResponseEntity<List<WaitingUserResponse>>을 유지하는 것이 좋습니다.

-public ResponseEntity<?> getWaitingUsersWithScore(@PathVariable Long storeId) {
+public ResponseEntity<List<WaitingUserResponse>> getWaitingUsersWithScore(@PathVariable Long storeId) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public ResponseEntity<?> getWaitingUsersWithScore(@PathVariable Long storeId) {
public ResponseEntity<List<WaitingUserResponse>> getWaitingUsersWithScore(@PathVariable Long storeId) {
🤖 Prompt for AI Agents
In
nowait-app-admin-api/src/main/java/com/nowait/applicationadmin/reservation/controller/ReservationController.java
at line 39, the method return type is declared as ResponseEntity<?> which
reduces type safety and obscures the API contract. Change the return type to
ResponseEntity<List<WaitingUserResponse>> to maintain type specificity and
clarity about the response content.

List<WaitingUserResponse> response = reservationService.getAllWaitingUserDetails(storeId);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -90,6 +92,7 @@ public CallGetResponseDto updateReservationStatus(Long reservationId, Reservatio
@Transactional(readOnly = true)
public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) {
List<ZSetOperations.TypedTuple<String>> waitingList = waitingRedisRepository.getAllWaitingWithScore(storeId);
System.out.println(waitingList);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

디버그 출력문을 제거해주세요.

프로덕션 코드에서 System.out.println은 제거되어야 합니다. 로깅이 필요하다면 적절한 로거를 사용하세요.

-System.out.println(waitingList);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
System.out.println(waitingList);
🤖 Prompt for AI Agents
In
nowait-app-admin-api/src/main/java/com/nowait/applicationadmin/reservation/service/ReservationService.java
at line 95, remove the System.out.println statement used for debugging. If
logging is necessary, replace it with a proper logger call using the project's
logging framework instead of direct standard output.


return waitingList.stream()
.map(tuple -> {
Expand All @@ -100,18 +103,24 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) {
String status = waitingRedisRepository.getWaitingStatus(storeId, userId);

// 2. DB에서 userName, createdAt, reservationId 조회
String userName = null;
LocalDateTime createdAt = null;
Long reservationId = null;

Optional<Reservation> reservationOpt = reservationRepository.findByStore_StoreIdAndUserId(storeId, Long.valueOf(userId));
//TODO 개선필요 -> createAt 정확성 및 reservationhId 생성 방법(예약생성부터 DB에 박아야하나....)
String userName = userRepository.getReferenceById(Long.valueOf(userId)).getNickname();
LocalDateTime createdAt = LocalDateTime.now();
String reservationId = String.valueOf(
ThreadLocalRandom.current().nextInt(1, 100));

Comment on lines +107 to +111
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

예약 ID 생성 로직에 일관성 문제가 있습니다.

현재 로직에서 예약이 없을 때 랜덤 ID를 생성하고, 예약이 있을 때는 데이터베이스 ID를 사용하는 것은 일관성이 없습니다. 또한 createdAt을 현재 시간으로 설정하는 것도 실제 예약 생성 시간과 다를 수 있어 혼란을 야기할 수 있습니다.

TODO 주석에서도 언급된 것처럼, 예약 생성 시점부터 DB에 저장하거나 일관된 ID 생성 전략을 수립해야 합니다.

-//TODO 개선필요 -> createAt 정확성 및 reservationhId 생성 방법(예약생성부터 DB에 박아야하나....)
-String userName = userRepository.getReferenceById(Long.valueOf(userId)).getNickname();
-LocalDateTime createdAt = LocalDateTime.now();
-String reservationId = String.valueOf(
-    ThreadLocalRandom.current().nextInt(1, 100));
+// 예약이 없는 경우의 기본값 설정을 명확히 하고 일관성 있게 처리
+String userName = null;
+LocalDateTime createdAt = null;
+String reservationId = null;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
nowait-app-admin-api/src/main/java/com/nowait/applicationadmin/reservation/service/ReservationService.java
around lines 107 to 111, the reservation ID generation is inconsistent by using
a random ID when no reservation exists and a database ID otherwise, and the
createdAt timestamp is set to the current time rather than the actual
reservation creation time. To fix this, implement a consistent ID generation
strategy that either always uses the database-generated ID or a unified method,
and ensure the createdAt timestamp reflects the actual reservation creation
time, ideally by setting it when the reservation is persisted to the database.

Optional<Reservation> reservationOpt = reservationRepository.findByStore_StoreIdAndUserIdAndRequestedAtBetween(
storeId, Long.valueOf(userId), LocalDate.now().atStartOfDay(), LocalDate.now().atTime(LocalTime.MAX));
if (reservationOpt.isPresent()) {
Reservation reservation = reservationOpt.get();
createdAt = reservation.getRequestedAt();
reservationId = reservation.getId();
reservationId = reservation.getId().toString();
userName = reservation.getUser().getNickname();
} else {
}



return new WaitingUserResponse(
reservationId != null ? reservationId.toString() : null,
userId,
Expand All @@ -129,7 +138,11 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) {
// 완료 or 취소 처리된 대기 리스트 조회
@Transactional(readOnly = true)
public List<WaitingUserResponse> getCompletedWaitingUserDetails(Long storeId) {
List<Reservation> reservations = reservationRepository.findAllByStore_StoreId(storeId);
List<Reservation> reservations = reservationRepository.findAllByStore_StoreIdAndStatusInAndRequestedAtBetween(
storeId,
List.of(ReservationStatus.CONFIRMED, ReservationStatus.CANCELLED),
LocalDate.now().atStartOfDay(),
LocalDate.now().atTime(LocalTime.MAX));

return reservations.stream()
.map(r -> WaitingUserResponse.fromEntity(r))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public interface ReservationRepository extends JpaRepository<Reservation, Long>

Optional<Reservation> findByStore_StoreIdAndUserId(Long storeId, Long userId);

Optional<Reservation> findByStore_StoreIdAndUserIdAndRequestedAtBetween(Long storeId, Long userId, LocalDateTime start, LocalDateTime end);
Optional<Reservation> findByStore_StoreIdAndUserIdAndRequestedAtBetween(
Long storeId, Long userId, LocalDateTime start, LocalDateTime end);

List<Reservation> findAllByStore_StoreIdAndStatusInAndRequestedAtBetween(
Long storeId, List<ReservationStatus> statuses, LocalDateTime start, LocalDateTime end);
Optional<Reservation> findByStore_StoreIdAndUserIdAndStatusInAndRequestedAtBetween(
Long storeId,
Long userId,
Expand Down