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 @@ -3,6 +3,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -63,4 +65,37 @@ public ResponseEntity<?> createQueue(
)
);
}

@GetMapping("/get/queue/redis/{storeId}")
@Operation(summary = "본인 대기열 조회", description = "특정 주점에 대한 본인 대기열 조회")
@ApiResponse(responseCode = "200", description = "본인 대기열 조회")
public ResponseEntity<?> getQueue(
@PathVariable Long storeId,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User
) {
WaitingResponseDto response = reservationService.myWaitingInfo(storeId,customOAuth2User);
return ResponseEntity
.ok()
.body(
ApiUtils.success(
response
)
);
}

@DeleteMapping("/delete/queue/redis/{storeId}")
@Operation(summary = "내 대기열 취소", description = "특정 주점에 대한 대기열 취소")
@ApiResponse(responseCode = "200", description = "대기열 취소")
public ResponseEntity<?> deleteQueue(
@PathVariable Long storeId,
@AuthenticationPrincipal CustomOAuth2User customOAuth2User
) {
return ResponseEntity
.ok()
.body(
ApiUtils.success(
reservationService.cancelWaiting(storeId,customOAuth2User)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean addToWaitingQueue(Long storeId, String userId, Integer partySize,
public Integer getPartySize(Long storeId, String userId) {
String partyKey = RedisKeyUtils.buildWaitingPartySizeKeyPrefix() + storeId;
Object value = redisTemplate.opsForHash().get(partyKey, userId);
return value == null ? null : Integer.valueOf(value.toString());
return Integer.valueOf(value.toString());
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

null 체크 제거로 인한 NPE 위험

Redis에서 값을 가져올 때 null 체크를 제거하면 키가 존재하지 않을 경우 NullPointerException이 발생합니다.

다음과 같이 수정하여 안전한 처리를 보장하세요:

-		return Integer.valueOf(value.toString());
+		return value != null ? Integer.valueOf(value.toString()) : null;

또는 기본값을 반환하도록 수정:

-		return Integer.valueOf(value.toString());
+		return value != null ? Integer.valueOf(value.toString()) : 0;
📝 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
return Integer.valueOf(value.toString());
return value != null
? Integer.valueOf(value.toString())
: 0;
🤖 Prompt for AI Agents
In
nowait-app-user-api/src/main/java/com/nowait/applicationuser/reservation/repository/WaitingRedisRepository.java
at line 30, the code directly converts a Redis value to Integer without checking
for null, which can cause a NullPointerException if the key does not exist. Add
a null check before converting the value, and return a default value (e.g., 0)
or handle the null case safely to prevent the exception.

}

public Long getRank(Long storeId, String userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nowait.applicationuser.reservation.dto.WaitingResponseDto;
import com.nowait.applicationuser.reservation.repository.WaitingRedisRepository;
import com.nowait.common.enums.ReservationStatus;
import com.nowait.common.enums.Role;
import com.nowait.domaincorerdb.reservation.entity.Reservation;
import com.nowait.domaincorerdb.reservation.exception.DuplicateReservationException;
import com.nowait.domaincorerdb.reservation.repository.ReservationRepository;
Expand Down Expand Up @@ -42,6 +43,12 @@ public WaitingResponseDto registerWaiting(
.orElseThrow(StoreNotFoundException::new);
if (Boolean.FALSE.equals(store.getIsActive()))
throw new StoreWaitingDisabledException();
// User Role 검증 추가
User user = userRepository.findById(customOAuth2User.getUserId())
.orElseThrow(UserNotFoundException::new);
if (user.getRole() == Role.MANAGER) {
throw new IllegalArgumentException("Manager cannot register waiting");
}

String userId = customOAuth2User.getUserId().toString();
long timestamp = System.currentTimeMillis();
Expand All @@ -59,9 +66,10 @@ public WaitingResponseDto registerWaiting(
.build();
}

public WaitingResponseDto myWaitingInfo(Long storeId, String userId) {
public WaitingResponseDto myWaitingInfo(Long storeId, CustomOAuth2User customOAuth2User) {
String userId = customOAuth2User.getUserId().toString();
// 입력 검증 추가
if (storeId == null || userId == null || userId.trim().isEmpty()) {
if (storeId == null || userId.trim().isEmpty()) {
throw new IllegalArgumentException("Invalid storeId or userId");
}
Long rank = waitingRedisRepository.getRank(storeId, userId);
Expand All @@ -72,8 +80,9 @@ public WaitingResponseDto myWaitingInfo(Long storeId, String userId) {
.build();
}

public boolean cancelWaiting(Long storeId, String userId) {
if (storeId == null || userId == null || userId.trim().isEmpty()) {
public boolean cancelWaiting(Long storeId, CustomOAuth2User customOAuth2User) {
String userId = customOAuth2User.getUserId().toString();
if (storeId == null || userId.trim().isEmpty()) {
throw new IllegalArgumentException("Invalid storeId or userId");
}
// 대기열에서 제거 및 결과 반환
Expand Down