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 @@ -18,6 +18,9 @@ public class WaitingUserResponse {
@Schema(description = "예약 ID", example = "16-20240201-0002")
private String reservationNumber;

@Schema(description = "휴대폰 번호", example = "010-1234-5678")
private String phoneNumber;

@Schema(description = "유저 ID", example = "16")
private String userId;

Expand Down Expand Up @@ -47,18 +50,21 @@ public static WaitingUserResponse fromEntity(Reservation reservation) {
.reservationNumber(reservation.getReservationNumber())
.userId(reservation.getUser().getId().toString())
.partySize(reservation.getPartySize())
.phoneNumber(reservation.getUser().getPhoneNumber())
.userName(reservation.getUser().getNickname())
.createdAt(reservation.getRequestedAt())
.updatedAt(reservation.getUpdatedAt())
.status(reservation.getStatus().name())
.build();
}

public static WaitingUserResponse fromRedis(String reservationId, String userId, Integer partySize, String userName,
LocalDateTime createdAt, LocalDateTime calledAt,String status, Double score) {
public static WaitingUserResponse fromRedis(String reservationId, String userId, String phoneNumber,
Integer partySize, String userName,
LocalDateTime createdAt, LocalDateTime calledAt, String status, Double score) {
return WaitingUserResponse.builder()
.reservationNumber(reservationId)
.userId(userId)
.phoneNumber(phoneNumber)
.partySize(partySize)
.userName(userName)
.createdAt(createdAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
Expand Down Expand Up @@ -125,11 +125,17 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) {
List<Long> userIdLongs = userIds.stream()
.map(Long::valueOf)
.toList();
Map<String, String> nicknameMap = userRepository.findAllById(userIdLongs).stream()
.collect(Collectors.toMap(
u -> u.getId().toString(),
User::getNickname
));

List<User> userList = userRepository.findByIdIn(userIdLongs);

Map<String, String> nicknameMap = new HashMap<>(userList.size());
Map<String, String> phoneNumberMap = new HashMap<>(userList.size());

for (User user : userList) {
String key = user.getId().toString();
nicknameMap.put(key, user.getNickname());
phoneNumberMap.put(key, user.getPhoneNumber());
}

// 4) Redis 파이프라인: partySize, status, reservationId
String pk = RedisKeyUtils.buildWaitingPartySizeKeyPrefix() + storeId;
Expand Down Expand Up @@ -174,9 +180,11 @@ public List<WaitingUserResponse> getAllWaitingUserDetails(Long storeId) {
: null;

String userName = nicknameMap.getOrDefault(userId, "Unknown");
String phoneNumber = phoneNumberMap.getOrDefault(userId, "Unknown");

result.add(
WaitingUserResponse.fromRedis(reservationId, userId, partySize, userName, createdAt, calledAt, status,
WaitingUserResponse.fromRedis(reservationId, userId, phoneNumber, partySize, userName, createdAt,
calledAt, status,
score));
}

Expand Down Expand Up @@ -269,8 +277,10 @@ public EntryStatusResponseDto processEntryStatus(Long storeId, String userId, Me
} else {
if (reservationNumber != null) {
try {
waitingPermitLuaRepository.removeActiveMember(userId, String.valueOf(storeId), reservationNumber);
} catch (Exception ignore) {}
waitingPermitLuaRepository.removeActiveMember(userId, String.valueOf(storeId),
reservationNumber);
} catch (Exception ignore) {
}
}

// 2) 이미 취소(CANCELLED)된 경우: DB 레코드 찾아 바로 CONFIRMED 로 전환
Expand Down Expand Up @@ -323,7 +333,6 @@ public EntryStatusResponseDto processEntryStatus(Long storeId, String userId, Me
}
}


/**
* 공통 메서드
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nowait.domaincorerdb.user.repository;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -11,5 +13,6 @@
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
Optional<User> findByNickname(String nickName);
List<User> findByIdIn(Collection<Long> ids);
boolean existsByPhoneNumberAndIdNot(String phoneNumber, Long id);
}