-
Notifications
You must be signed in to change notification settings - Fork 0
예약 대기열 기능을 구현했습니다. #11
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
Merged
The head ref may contain hidden characters: "feature/\uC608\uC57D-\uB300\uAE30\uC5F4-\uAE30\uB2A5-\uAD6C\uD604"
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/yscp/catchtable/application/queue/StoreQueueService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.yscp.catchtable.application.queue; | ||
|
|
||
| import com.yscp.catchtable.application.queue.dto.StoreQueueDto; | ||
| import com.yscp.catchtable.exception.BadRequestError; | ||
| import com.yscp.catchtable.exception.CatchTableException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class StoreQueueService { | ||
| private final RedisTemplate<String, String> redisTemplate; | ||
|
|
||
| public void registerWaiting(StoreQueueDto storeQueueDto) { | ||
|
|
||
| Boolean result = redisTemplate.opsForZSet().addIfAbsent(storeQueueDto.key(), | ||
| storeQueueDto.value(), | ||
| storeQueueDto.score()); | ||
|
|
||
| if (Boolean.FALSE.equals(result)) { | ||
| throw new CatchTableException(BadRequestError.ALREADY_REGISTER_WAITING); | ||
| } | ||
|
|
||
| redisTemplate.expire(storeQueueDto.key(), Duration.ofMinutes(7L)); | ||
|
|
||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/yscp/catchtable/application/queue/dto/StoreQueueDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.yscp.catchtable.application.queue.dto; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| public record StoreQueueDto( | ||
| String storeReserveIdx, | ||
| String userIdx | ||
| ) { | ||
| private static final String WAITING_KEY_FORMAT = "store:%s:waiting:v1:%s"; | ||
|
|
||
| public String key() { | ||
| return String.format(WAITING_KEY_FORMAT, storeReserveIdx, userIdx); | ||
| } | ||
|
|
||
| public String value() { | ||
| return userIdx; | ||
| } | ||
|
|
||
| public double score() { | ||
| return Instant.now().toEpochMilli(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/yscp/catchtable/application/reserve/ReservesInDayDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.yscp.catchtable.application.reserve; | ||
|
|
||
| import com.yscp.catchtable.application.reserve.dto.ReserveInDayDto; | ||
| import com.yscp.catchtable.domain.reserve.entity.ReserveData; | ||
| import org.springframework.util.CollectionUtils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public record ReservesInDayDto( | ||
| List<ReserveInDayDto> reserves | ||
| ) { | ||
| public static ReservesInDayDto from(List<ReserveData> reserveDates) { | ||
| if (CollectionUtils.isEmpty(reserveDates)) { | ||
| return new ReservesInDayDto(new ArrayList<>()); | ||
| } | ||
|
|
||
| return new ReservesInDayDto(convert(reserveDates)); | ||
| } | ||
|
|
||
| private static List<ReserveInDayDto> convert(List<ReserveData> reserveDates) { | ||
| return reserveDates.stream() | ||
| .map(reserveData -> new ReserveInDayDto( | ||
| reserveData.getIdx(), | ||
| reserveData.getReserveTime(), | ||
| reserveData.getMaxUserCount() | ||
| )).toList(); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/yscp/catchtable/application/reserve/dto/ReserveInDayDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.yscp.catchtable.application.reserve.dto; | ||
|
|
||
| public record ReserveInDayDto( | ||
| Long idx, | ||
| String reserveTime, | ||
| Integer maxUserCount | ||
| ) { | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/yscp/catchtable/application/store/mapper/StoreQueueMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.yscp.catchtable.application.store.mapper; | ||
|
|
||
| import com.yscp.catchtable.application.queue.dto.StoreQueueDto; | ||
| import com.yscp.catchtable.presentation.store.dto.StoreQueueRequestDto; | ||
| import lombok.experimental.UtilityClass; | ||
|
|
||
| @UtilityClass | ||
| public class StoreQueueMapper { | ||
| public static StoreQueueDto toQueueDto(StoreQueueRequestDto storeQueueRequestDto) { | ||
| return new StoreQueueDto( | ||
| storeQueueRequestDto.storeReserveIdx().toString(), | ||
| storeQueueRequestDto.userIdx() | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/yscp/catchtable/presentation/reserve/ReserveController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.yscp.catchtable.presentation.reserve; | ||
|
|
||
| import com.yscp.catchtable.application.reserve.ReserveService; | ||
| import com.yscp.catchtable.application.reserve.ReservesInDayDto; | ||
| import com.yscp.catchtable.presentation.reserve.dto.response.ReserveInDayResponseDtos; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| public class ReserveController { | ||
|
|
||
| private final ReserveService reserveService; | ||
|
|
||
| @GetMapping("/store/reserves/{storeIdx}") | ||
| public ResponseEntity<ReserveInDayResponseDtos> getReservesInDay(@PathVariable Long storeIdx, | ||
| @RequestParam LocalDate date) { | ||
|
|
||
| ReservesInDayDto reservesInDay = reserveService.getReservesInDay(storeIdx, date); | ||
|
|
||
| return ResponseEntity.ok(ReserveInDayResponseDtos.from(reservesInDay)); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
...n/java/com/yscp/catchtable/presentation/reserve/dto/response/ReserveInDayResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.yscp.catchtable.presentation.reserve.dto.response; | ||
|
|
||
| public record ReserveInDayResponseDto( | ||
| Long idx, | ||
| String reserveTime, | ||
| Integer maxUserCount | ||
| ) { | ||
| } |
28 changes: 28 additions & 0 deletions
28
.../java/com/yscp/catchtable/presentation/reserve/dto/response/ReserveInDayResponseDtos.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.yscp.catchtable.presentation.reserve.dto.response; | ||
|
|
||
| import com.yscp.catchtable.application.reserve.ReservesInDayDto; | ||
| import com.yscp.catchtable.application.reserve.dto.ReserveInDayDto; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public record ReserveInDayResponseDtos( | ||
| List<ReserveInDayResponseDto> reserves | ||
| ) { | ||
| public static ReserveInDayResponseDtos from(ReservesInDayDto reservesInDay) { | ||
| if (reservesInDay == null) { | ||
| return new ReserveInDayResponseDtos(new ArrayList<>()); | ||
| } | ||
|
|
||
| return new ReserveInDayResponseDtos(convert(reservesInDay.reserves())); | ||
| } | ||
|
|
||
| private static List<ReserveInDayResponseDto> convert(List<ReserveInDayDto> reservesInDay) { | ||
| return reservesInDay.stream() | ||
| .map(reserveInDayDto -> new ReserveInDayResponseDto( | ||
| reserveInDayDto.idx(), | ||
| reserveInDayDto.reserveTime(), | ||
| reserveInDayDto.maxUserCount() | ||
| )).toList(); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/yscp/catchtable/presentation/store/StoreQueueController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.yscp.catchtable.presentation.store; | ||
|
|
||
| import com.yscp.catchtable.application.queue.StoreQueueService; | ||
| import com.yscp.catchtable.application.store.mapper.StoreQueueMapper; | ||
| import com.yscp.catchtable.presentation.store.dto.StoreQueueRequestDto; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| public class StoreQueueController { | ||
| private final StoreQueueService storeQueueService; | ||
|
|
||
| @PostMapping("/store/reservation/enter") | ||
| public ResponseEntity<Void> enter(@RequestBody StoreQueueRequestDto storeQueueRequestDto) { | ||
| storeQueueService.registerWaiting(StoreQueueMapper.toQueueDto(storeQueueRequestDto)); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/yscp/catchtable/presentation/store/dto/StoreQueueRequestDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.yscp.catchtable.presentation.store.dto; | ||
|
|
||
| public record StoreQueueRequestDto( | ||
| Long storeReserveIdx, | ||
| String userIdx | ||
| ) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"_" 이것은 무엇인가요ㅎㅎ
의도한건가요?
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.
메소드네이밍으로 함수 지을 때 _을 사용할 경우 연관관계 객체의 필드를 사용할 수 있는 것 같더라구요!
Property Expressions 관련 내용을 참고했습니다!
(https://docs.spring.io/spring-data/commons/reference/repositories/query-methods-details.html)