-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor : User 웨이팅 등록 및 삭제 기능 리팩토링 #349
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
Changes from all commits
725d823
3a98b5b
2283de1
40eedd0
bad3544
384c4dd
347ec51
b275e50
c19cb11
9602ba9
7f883f8
b47a5ab
5736dcc
83a37a9
851a464
432bbd4
3dd0023
de996a6
e40ee5d
9a94ba5
a248f73
d303b9d
117fa93
d00b1c5
ca8feec
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,80 @@ | ||
| package com.nowait.applicationuser.waiting.controller; | ||
|
|
||
| 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.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.nowait.applicationuser.waiting.dto.CancelWaitingRequest; | ||
| import com.nowait.applicationuser.waiting.dto.CancelWaitingResponse; | ||
| import com.nowait.applicationuser.waiting.dto.RegisterWaitingRequest; | ||
| import com.nowait.applicationuser.waiting.dto.RegisterWaitingResponse; | ||
| import com.nowait.applicationuser.waiting.service.WaitingService; | ||
| import com.nowait.common.api.ApiUtils; | ||
| import com.nowait.domainuserrdb.oauth.dto.CustomOAuth2User; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Tag(name = "Waiting API", description = "예약 API -리팩토링 중-") | ||
| @RestController | ||
| @RequestMapping("/v2/users/me/waitings") | ||
| @RequiredArgsConstructor | ||
| public class WaitingController { | ||
| private final WaitingService waitingService; | ||
|
|
||
| /** | ||
| * 대기열 리팩토링용 API | ||
| */ | ||
| @PostMapping("/{publicCode}") | ||
| @Operation(summary = "대기열 리팩토링용 API", description = "대기열 리팩토링용 API") | ||
| public ResponseEntity<?> registerWaiting( | ||
| @AuthenticationPrincipal CustomOAuth2User customOAuth2User, | ||
| @PathVariable String publicCode, | ||
| @RequestBody RegisterWaitingRequest request, | ||
| HttpServletRequest httpServletRequest | ||
| ) { | ||
| RegisterWaitingResponse registerWaitingResponse = waitingService.registerWaiting( | ||
| customOAuth2User, | ||
| publicCode, | ||
| request, | ||
| httpServletRequest | ||
| ); | ||
|
|
||
| return ResponseEntity | ||
| .ok() | ||
| .body( | ||
| ApiUtils.success( | ||
| registerWaitingResponse | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @DeleteMapping("/{publicCode}") | ||
| @Operation(summary = "대기열 리팩토링용 API", description = "대기 취소") | ||
| public ResponseEntity<?> cancelWaiting( | ||
| @AuthenticationPrincipal CustomOAuth2User customOAuth2User, | ||
| @PathVariable String publicCode, | ||
| @RequestBody CancelWaitingRequest request | ||
| ) { | ||
| CancelWaitingResponse cancelWaitingResponse = waitingService.cancelWaiting( | ||
| customOAuth2User, | ||
| publicCode, | ||
| request | ||
| ); | ||
|
|
||
| return ResponseEntity | ||
| .ok() | ||
| .body( | ||
| ApiUtils.success( | ||
| cancelWaitingResponse | ||
| ) | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.nowait.applicationuser.waiting.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class CancelWaitingRequest { | ||
| private String waitingNumber; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.nowait.applicationuser.waiting.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.nowait.common.enums.ReservationStatus; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class CancelWaitingResponse { | ||
| private String waitingNumber; | ||
| private Long storeId; | ||
| private ReservationStatus reservationStatus; | ||
| private LocalDateTime canceledAt; | ||
| private String message; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.nowait.applicationuser.waiting.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class RegisterWaitingRequest { | ||
| private Integer partySize; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.nowait.applicationuser.waiting.dto; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class RegisterWaitingResponse { | ||
| private final String waitingNumber; | ||
| private final int partySize; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.nowait.applicationuser.waiting.dto; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class WaitingIdempotencyValue { | ||
| private String state; | ||
| private RegisterWaitingResponse response; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.nowait.applicationuser.waiting.event; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class AddWaitingRegisterEvent { | ||
| @NotNull | ||
| private final Long storeId; | ||
| @NotNull | ||
| private final Long userId; | ||
| @NotNull | ||
| private final LocalDateTime timestamp; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.nowait.applicationuser.waiting.event.listener; | ||
|
|
||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.event.TransactionPhase; | ||
| import org.springframework.transaction.event.TransactionalEventListener; | ||
|
|
||
| import com.nowait.applicationuser.waiting.event.AddWaitingRegisterEvent; | ||
| import com.nowait.domaincoreredis.reservation.repository.WaitingRedisRepository; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AddWaitingRegisterListener { | ||
|
|
||
| private final WaitingRedisRepository waitingRedisRepository; | ||
|
|
||
| @Async | ||
| @TransactionalEventListener( | ||
| classes = AddWaitingRegisterEvent.class, | ||
| phase = TransactionPhase.AFTER_COMMIT | ||
| ) | ||
| public void onAddWaitingRegister(AddWaitingRegisterEvent event) { | ||
| waitingRedisRepository.addWaiting(event.getStoreId(), event.getUserId(), event.getTimestamp()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.nowait.applicationuser.waiting.redis; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.nowait.applicationuser.waiting.dto.RegisterWaitingResponse; | ||
| import com.nowait.applicationuser.waiting.dto.WaitingIdempotencyValue; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class WaitingIdempotencyRepository { | ||
|
|
||
| private final RedisTemplate<String, String> redisTemplate; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| private static final Duration TTL = Duration.ofMinutes(10); | ||
|
|
||
| public Optional<WaitingIdempotencyValue> findByKey(String key) { | ||
| String value = redisTemplate.opsForValue().get(key); | ||
|
|
||
| if (value == null) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| try { | ||
| return Optional.of( | ||
| objectMapper.readValue(value, WaitingIdempotencyValue.class) | ||
| ); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Failed to deserialize value from Redis", e); | ||
| } | ||
| } | ||
|
|
||
| public void saveIdempotencyValue(String key, RegisterWaitingResponse response) { | ||
| WaitingIdempotencyValue waitingIdempotencyValue = new WaitingIdempotencyValue( | ||
| "COMPLETED", | ||
| response | ||
| ); | ||
|
|
||
| try { | ||
| String jsonValue = objectMapper.writeValueAsString(waitingIdempotencyValue); | ||
| redisTemplate.opsForValue().set(key, jsonValue, TTL); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Failed to serialize value for Redis", e); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+15
to
+53
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for usage patterns of findByKey and saveIdempotencyValue
rg -n -A 10 "findByKey|saveIdempotencyValue" --type javaRepository: GTable/NoWait_BE_MultiModule Length of output: 7881 🏁 Script executed: #!/bin/bash
# Check for distributed lock usage or synchronization around idempotency handling
rg -n -B 5 "saveIdempotencyValue" --type java | head -50
# Check if there are any `@Lock` or synchronization mechanisms
rg -n "@Lock|@Transactional|synchronized" --type java -A 3 | grep -A 3 "registerWaiting"Repository: GTable/NoWait_BE_MultiModule Length of output: 2276
WaitingService의
🤖 Prompt for AI Agents
Contributor
Author
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. 해당 사항 인지하고 있어. #348 하위 이슈로 등록해줘 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. 🧩 Analysis chain
🏁 Script executed: Length of output: 58
Issue
|
||
Uh oh!
There was an error while loading. Please reload this page.