From d0411463d95644a7028e9381a3bb5aab75d81fdc Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 00:19:27 +0900 Subject: [PATCH 01/21] =?UTF-8?q?rename=20:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java | 2 ++ .../waiting/dto/{ => request}/CreateWaitingRequest.java | 2 +- .../catchtable/waiting/dto/{ => response}/WaitingResponse.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/dto/{ => request}/CreateWaitingRequest.java (80%) rename src/main/java/com/prgrms/catchtable/waiting/dto/{ => response}/WaitingResponse.java (82%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 5a11c521..dbe2fc77 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -5,6 +5,8 @@ import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.WaitingResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java b/src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java similarity index 80% rename from src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java index 4b9f9205..09a05a70 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/CreateWaitingRequest.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/request/CreateWaitingRequest.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.dto; +package com.prgrms.catchtable.waiting.dto.request; import jakarta.validation.constraints.Positive; import lombok.Builder; diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java similarity index 82% rename from src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java index 969c8e8c..af4106dc 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java @@ -1,4 +1,4 @@ -package com.prgrms.catchtable.waiting.dto; +package com.prgrms.catchtable.waiting.dto.response; import lombok.Builder; From a6a50b275aa927c6f15cd7c99d7abfcde6674ab0 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 00:22:06 +0900 Subject: [PATCH 02/21] =?UTF-8?q?style=20:=20dto=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MemberWaitingController.java | 20 +++++++++---------- .../catchtable/waiting/dto/WaitingMapper.java | 6 +++--- ...sponse.java => MemberWaitingResponse.java} | 2 +- .../waiting/service/MemberWaitingService.java | 12 +++++------ .../MemberWaitingControllerDocsTest.java | 6 +++--- .../MemberWaitingControllerTest.java | 2 +- .../service/MemberWaitingServiceTest.java | 12 +++++------ 7 files changed, 30 insertions(+), 30 deletions(-) rename src/main/java/com/prgrms/catchtable/waiting/dto/response/{WaitingResponse.java => MemberWaitingResponse.java} (87%) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index e7dfb94a..6a0e32a1 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.waiting.controller; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.service.MemberWaitingService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -23,29 +23,29 @@ public class MemberWaitingController { private final MemberWaitingService memberWaitingService; @PostMapping("/{shopId}/{memberId}") - public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, + public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - WaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); return ResponseEntity.ok(response); } @PatchMapping("/{memberId}") - public ResponseEntity postponeWaiting( + public ResponseEntity postponeWaiting( @PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.postponeWaiting(memberId); + MemberWaitingResponse response = memberWaitingService.postponeWaiting(memberId); return ResponseEntity.ok(response); } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.cancelWaiting(memberId); + public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { + MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } @GetMapping("/{memberId}") - public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { - WaitingResponse response = memberWaitingService.getWaiting(memberId); + public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index dbe2fc77..725a0572 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -6,7 +6,7 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.response.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -23,8 +23,8 @@ public static Waiting toWaiting(CreateWaitingRequest request, int waitingNumber, } // entity -> dto - public static WaitingResponse toWaitingResponse(Waiting waiting, Long rank) { - return WaitingResponse.builder() + public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank) { + return MemberWaitingResponse.builder() .waitingId(waiting.getId()) .shopId(waiting.getShop().getId()) .shopName(waiting.getShop().getName()) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java similarity index 87% rename from src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java rename to src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java index af4106dc..eaba99df 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/WaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/MemberWaitingResponse.java @@ -3,7 +3,7 @@ import lombok.Builder; @Builder -public record WaitingResponse( +public record MemberWaitingResponse( Long waitingId, Long shopId, String shopName, diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java index 4025e774..631dad9f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/MemberWaitingService.java @@ -15,8 +15,8 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalDate; @@ -39,7 +39,7 @@ public class MemberWaitingService { private final ShopRepository shopRepository; private final WaitingLineRepository waitingLineRepository; - public WaitingResponse createWaiting(Long shopId, Long memberId, + public MemberWaitingResponse createWaiting(Long shopId, Long memberId, CreateWaitingRequest request) { // 연관 엔티티 조회 Member member = getMemberEntity(memberId); @@ -63,7 +63,7 @@ public WaitingResponse createWaiting(Long shopId, Long memberId, } @Transactional - public WaitingResponse postponeWaiting(Long memberId) { + public MemberWaitingResponse postponeWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); @@ -77,7 +77,7 @@ public WaitingResponse postponeWaiting(Long memberId) { } @Transactional - public WaitingResponse cancelWaiting(Long memberId) { + public MemberWaitingResponse cancelWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); @@ -89,7 +89,7 @@ public WaitingResponse cancelWaiting(Long memberId) { } @Transactional(readOnly = true) - public WaitingResponse getWaiting(Long memberId) { + public MemberWaitingResponse getWaiting(Long memberId) { Member member = getMemberEntity(memberId); Waiting waiting = getWaitingEntityInProgress(member); diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java index 64e7fca8..6b7a0360 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerDocsTest.java @@ -14,8 +14,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.prgrms.catchtable.common.restdocs.RestDocsSupport; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.service.MemberWaitingService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -37,7 +37,7 @@ void createWaiting() throws Exception { CreateWaitingRequest request = CreateWaitingRequest .builder() .peopleCount(2).build(); - WaitingResponse response = WaitingResponse.builder() + MemberWaitingResponse response = MemberWaitingResponse.builder() .waitingId(201L) .shopId(1L) .shopName("shop1") diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java index 1627b23b..062c6098 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/MemberWaitingControllerTest.java @@ -21,7 +21,7 @@ import com.prgrms.catchtable.shop.fixture.ShopFixture; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index d5a1d959..18d29fc0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -15,8 +15,8 @@ import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.dto.CreateWaitingRequest; -import com.prgrms.catchtable.waiting.dto.WaitingResponse; +import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; +import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.time.LocalTime; @@ -68,7 +68,7 @@ void createWaiting() { given(waitingLineRepository.findRank(shop.getId(), waiting.getId())).willReturn(1L); //when - WaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(1L, 1L, request); //then assertAll( () -> assertThat(response.peopleCount()).isEqualTo(2), @@ -94,7 +94,7 @@ void postponeWaiting() { doNothing().when(waiting).decreasePostponeRemainingCount(); //when - WaitingResponse response = memberWaitingService.postponeWaiting(1L); + MemberWaitingResponse response = memberWaitingService.postponeWaiting(1L); //then assertAll( assertThat(response.peopleCount())::isNotNull, @@ -119,7 +119,7 @@ void cancelWaiting() { doNothing().when(waiting).changeStatusCanceled(); //when - WaitingResponse response = memberWaitingService.cancelWaiting(1L); + MemberWaitingResponse response = memberWaitingService.cancelWaiting(1L); //then assertAll( @@ -143,7 +143,7 @@ void getWaiting() { given(waiting.getShop()).willReturn(shop); given(waiting.getStatus()).willReturn(PROGRESS); //when - WaitingResponse response = memberWaitingService.getWaiting(1L); + MemberWaitingResponse response = memberWaitingService.getWaiting(1L); //then From e647fdc1193e1c4c887d3ccddf86508363b981ce Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:02:55 +0900 Subject: [PATCH 03/21] =?UTF-8?q?refactor=20:=20waitingRepository=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/fixture/WaitingFixture.java | 8 ++++++-- .../waiting/repository/WaitingRepositoryTest.java | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index b27f5164..2f888593 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,8 +1,13 @@ package com.prgrms.catchtable.waiting.fixture; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; + import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.domain.WaitingStatus; +import java.time.LocalDateTime; +import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -17,8 +22,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - waiting.completeWaiting(); + ReflectionTestUtils.setField(waiting, "status", COMPLETED) ; return waiting; } - } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 235d142b..f8beb3a5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -14,6 +14,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -40,7 +41,6 @@ class WaitingRepositoryTest { private ShopRepository shopRepository; private Shop shop; private Member member1, member2, member3; - private Waiting yesterdayWaiting, completedWaiting, normalWaiting; @BeforeEach void setUp() { @@ -63,9 +63,9 @@ void clear() { @DisplayName("특정 가게의 당일 대기 번호를 조회할 수 있다.") @Test void countByShopAndCreatedAtBetween() { - yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); - completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); - normalWaiting = WaitingFixture.waiting(member3, shop, 3); + Waiting yesterdayWaiting = WaitingFixture.waiting(member1, shop, 1); + Waiting completedWaiting = WaitingFixture.completedWaiting(member2, shop, 2); + Waiting normalWaiting = WaitingFixture.waiting(member3, shop, 3); waitingRepository.saveAll(List.of(yesterdayWaiting, completedWaiting, normalWaiting)); ReflectionTestUtils.setField(yesterdayWaiting, "createdAt", @@ -78,4 +78,5 @@ void countByShopAndCreatedAtBetween() { //then assertThat(count).isEqualTo(2L); //waiting2, waiting3 } + } \ No newline at end of file From 6ab5e4e7219a394518498ef94012d331692f2eca Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:16:22 +0900 Subject: [PATCH 04/21] =?UTF-8?q?feat=20:=20waitingRepository=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/repository/WaitingRepository.java | 7 +++++++ .../waiting/repository/WaitingRepositoryTest.java | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java index 3ae6e878..d07b806c 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/WaitingRepository.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.domain.WaitingStatus; import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -20,4 +21,10 @@ public interface WaitingRepository extends JpaRepository { + "where w.member = :member and w.status = :status") Optional findByMemberAndStatusWithShop(@Param("member") Member member, @Param("status") WaitingStatus status); + + @Query("select w from Waiting w where w.id in :ids") + List findByIds(@Param("ids") List ids); + + @Query("select w from Waiting w join fetch w.member where w.id = :id") + Optional findWaitingWithMember(@Param("id") Long id); } diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index f8beb3a5..0e45655b 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -79,4 +79,17 @@ void countByShopAndCreatedAtBetween() { assertThat(count).isEqualTo(2L); //waiting2, waiting3 } + @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") + @Test + void findByIdsWithMember(){ + Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); + Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); + waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); + List waitingIds = List.of(waiting1.getId(), waiting2.getId(), waiting3.getId()); + //when + List waitings = waitingRepository.findByIds(waitingIds); + //then + Assertions.assertThat(waitings).containsExactly(waiting1, waiting2, waiting3); + } } \ No newline at end of file From edab978cc7c9b4406e081c110419aca6890bab23 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:27:18 +0900 Subject: [PATCH 05/21] =?UTF-8?q?feat=20:=20waitingLineRepository=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/BasicWaitingLineRepository.java | 6 ++++++ .../waitingline/RedisWaitingLineRepository.java | 14 ++++++++++++++ .../waitingline/WaitingLineRepository.java | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java index 090ef8e6..3b0b8e11 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepository.java @@ -7,6 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Queue; @@ -33,6 +34,11 @@ public void entry(Long shopId, Long waitingId) { waitingLine.remove(); } + public List getShopWaitingIdsInOrder(Long shopId) { + Queue waitingLine = waitingLines.get(shopId); + return waitingLine.stream().toList(); + } + public void cancel(Long shopId, Long waitingId) { Queue waitingLine = waitingLines.get(shopId); validateIfWaitingExists(waitingLine, waitingId); diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index a3407dc6..92d7b09a 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -5,6 +5,8 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; import lombok.RequiredArgsConstructor; @@ -41,6 +43,18 @@ public Object execute(RedisOperations operations) }); } + public List getShopWaitingIdsInOrder(Long shopId){ + List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); + if (stringList == null) { + throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); + } + List longList = new ArrayList<>(stringList.stream() + .map(Long::parseLong) + .toList()); + Collections.reverse(longList); + return longList; + } + public void entry(Long shopId, Long waitingId) { validateIfWaitingExists(shopId, waitingId); redisTemplate.execute(new SessionCallback<>() { diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java index f80a9d5f..20960a0f 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/WaitingLineRepository.java @@ -1,5 +1,7 @@ package com.prgrms.catchtable.waiting.repository.waitingline; +import java.util.List; + public interface WaitingLineRepository { void save(Long shopId, Long waitingId); @@ -14,5 +16,7 @@ public interface WaitingLineRepository { Long getWaitingLineSize(Long shopId); + List getShopWaitingIdsInOrder(Long shopId); + void printWaitingLine(Long shopId); } From e1017f00d496bd36379d7f3f83605cda5f99d2fe Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:27:45 +0900 Subject: [PATCH 06/21] =?UTF-8?q?feat=20:=20waitingLineRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=90=9C=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BasicWaitingLineRepositoryTest.java | 16 ++++++++++++++++ .../RedisWaitingLineRepositoryTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index 1f40cc8c..ac7f77cd 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -112,4 +113,19 @@ void cancel() { .isEqualTo(2); } + @DisplayName("특정 가게의 웨이팅 아이디를 rank 순으로 가져온다.") + @Test + void getShopWaitingIdOrder() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + List waitingIds = repository.getShopWaitingIdsInOrder(shopId); + //then + System.out.println("waitingIds = " + waitingIds); + assertThat(waitingIds.get(0)).isEqualTo(1L); + } + } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java index 57b18eaf..15c2e311 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepositoryTest.java @@ -5,6 +5,7 @@ import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; +import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -119,4 +120,19 @@ void cancel() { assertThat(repository.findRank(1L, 3L)) .isEqualTo(2); } + + @DisplayName("특정 가게의 웨이팅 아이디를 rank 순으로 가져온다.") + @Test + void getShopWaitingIdOrder() { + //given + Long shopId = 1L; + repository.save(shopId, 1L); + repository.save(shopId, 2L); + repository.save(shopId, 3L); + //when + List waitingIds = repository.getShopWaitingIdsInOrder(shopId); + //then + System.out.println("waitingIds = " + waitingIds); + assertThat(waitingIds.get(0)).isEqualTo(1L); + } } \ No newline at end of file From d0694f537fece4f29272b03afed31bd9014093a3 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:30:38 +0900 Subject: [PATCH 07/21] =?UTF-8?q?feat=20:=20owner=20=EA=B4=80=EB=A0=A8=20D?= =?UTF-8?q?TO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/OwnerWaitingListResponse.java | 9 +++++++++ .../waiting/dto/response/OwnerWaitingResponse.java | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java create mode 100644 src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java new file mode 100644 index 00000000..70af4cb2 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java @@ -0,0 +1,9 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import java.util.List; +import lombok.Builder; + +@Builder +public record OwnerWaitingListResponse ( + List shopWaitings +){} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java new file mode 100644 index 00000000..763236bb --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -0,0 +1,11 @@ +package com.prgrms.catchtable.waiting.dto.response; + +import lombok.Builder; + +@Builder +public record OwnerWaitingResponse ( + Long waitingId, + int waitingNumber, + Long rank, + int peopleCount +){} From f494bcdcd179374fe279fbb102130bdef8e443be Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 11:35:49 +0900 Subject: [PATCH 08/21] =?UTF-8?q?feat=20:=20dto=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=A7=A4=ED=95=91=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/waiting/dto/WaitingMapper.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 725a0572..52416bf7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -7,6 +7,10 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.request.CreateWaitingRequest; import com.prgrms.catchtable.waiting.dto.response.MemberWaitingResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingResponse; +import java.util.ArrayList; +import java.util.List; import lombok.NoArgsConstructor; @NoArgsConstructor(access = PRIVATE) @@ -35,4 +39,22 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .status(waiting.getStatus().getDescription()) .build(); } + + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank){ + return OwnerWaitingResponse.builder() + .waitingId(waiting.getId()) + .waitingNumber(waiting.getWaitingNumber()) + .rank(rank) + .peopleCount(waiting.getPeopleCount()) + .build(); + } + + public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings){ + long rank=1L; + List list = new ArrayList<>(); + for (Waiting waiting : waitings){ + list.add(toOwnerWaitingResponse(waiting,rank++)); + } + return new OwnerWaitingListResponse(list); + } } From 46ace9bc5b249c2fcd7c7a0615cc48a78edff7b7 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 12:09:58 +0900 Subject: [PATCH 09/21] =?UTF-8?q?feat=20:=20owner=20waiting=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/OwnerWaitingService.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java new file mode 100644 index 00000000..00681ac5 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -0,0 +1,36 @@ +package com.prgrms.catchtable.waiting.service; + +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_OWNER; +import static com.prgrms.catchtable.waiting.dto.WaitingMapper.toOwnerWaitingListResponse; + +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class OwnerWaitingService { + + private final WaitingRepository waitingRepository; + private final WaitingLineRepository waitingLineRepository; + private final OwnerRepository ownerRepository; + + @Transactional(readOnly = true) + public OwnerWaitingListResponse getOwnerAllWaiting(Long ownerId) { + Owner owner = ownerRepository.findById(ownerId) + .orElseThrow(() -> new BadRequestCustomException(NOT_EXIST_OWNER)); + List waitingIds = waitingLineRepository.getShopWaitingIdsInOrder( + owner.getShop().getId()); + List waitings = waitingRepository.findByIds(waitingIds); + return toOwnerWaitingListResponse(waitings); + } +} From 7c4962f76964e47376770cdf82bf270fcaa4e7ab Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 12:10:46 +0900 Subject: [PATCH 10/21] =?UTF-8?q?feat=20:=20=EA=B8=B0=EC=A1=B4=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=88=84=EB=9D=BD=EB=90=9C=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/MemberWaitingServiceTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 18d29fc0..0443b182 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -146,7 +146,11 @@ void getWaiting() { MemberWaitingResponse response = memberWaitingService.getWaiting(1L); //then - + assertAll( + assertThat(response.peopleCount())::isNotNull, + assertThat(response.rank())::isNotNull, + assertThat(response.waitingNumber())::isNotNull + ); } From 2ca04c692019a75c45da5bbdeeb251f71412e058 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:25:35 +0900 Subject: [PATCH 11/21] =?UTF-8?q?feat=20:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 1 + .../owner/fixture/OwnerFixture.java | 14 +++++ .../service/MemberWaitingServiceTest.java | 2 +- .../service/OwnerWaitingServiceTest.java | 59 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java diff --git a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java index a0b3afe4..b301f2e7 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -31,6 +31,7 @@ public enum ErrorCode { INTERNAL_SERVER_ERROR("내부 서버 오류입니다."), ALREADY_EXIST_OWNER("이미 존재하는 점주입니다"), + NOT_EXIST_OWNER("해당 아이디의 점주가 존재하지 않습니다."), BAD_REQUEST_EMAIL_OR_PASSWORD("이메일 혹은 비밀번호를 확인해주세요"), BAD_REQUEST_INPUT_GENDER_TYPE("성별 타입을 양식대로 입력해주세요"); diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 54089c3c..570b7904 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -29,6 +29,20 @@ public static Owner getOwner(String email, String password) { return owner; } + public static Owner getOwner(Shop shop){ + Owner owner = Owner.builder() + .name("ownerA") + .email("email") + .password("password") + .phoneNumber("010-3462-2480") + .gender(MALE) + .dateBirth(LocalDate.of(2000, 9, 13)) + .build(); + ReflectionTestUtils.setField(shop, "id", 1L); + owner.insertShop(shop); + return owner; + } + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ return JoinOwnerRequest.builder() .name("ownerA") diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java index 0443b182..bcc35fc0 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/MemberWaitingServiceTest.java @@ -129,7 +129,7 @@ void cancelWaiting() { ); } - @DisplayName("웨이팅를 조회할 수 있다.") + @DisplayName("점주의 웨이팅를 조회할 수 있다.") @Test void getWaiting() { //given diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java new file mode 100644 index 00000000..76d17a79 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -0,0 +1,59 @@ +package com.prgrms.catchtable.waiting.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class OwnerWaitingServiceTest { + + @Mock + private OwnerRepository ownerRepository; + + @Mock + private WaitingRepository waitingRepository; + + @Mock + private WaitingLineRepository waitingLineRepository; + + @InjectMocks + private OwnerWaitingService ownerWaitingService; + + @DisplayName("owner의 waiting 목록을 모두 가져온다.") + @Test + void getOwnerAllWaiting() { + //given + List waitingIds = List.of(1L); + Owner owner = mock(Owner.class); + Shop shop = mock(Shop.class); + Waiting waiting = mock(Waiting.class); + + given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); + given(owner.getShop()).willReturn(shop); + given(shop.getId()).willReturn(1L); + given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn(waitingIds); + given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); + + //when + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); + //then + assertThat(response).isNotNull(); + } +} \ No newline at end of file From 2f5829b81b7e6e3c7a95be8976e435d92c1d11d1 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:26:59 +0900 Subject: [PATCH 12/21] =?UTF-8?q?feat=20:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20controller=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java new file mode 100644 index 00000000..c907e0d9 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingController.java @@ -0,0 +1,25 @@ +package com.prgrms.catchtable.waiting.controller; + +import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.service.OwnerWaitingService; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RequestMapping("owner/waitings") +@RestController +public class OwnerWaitingController { + + private final OwnerWaitingService ownerWaitingService; + + @GetMapping("/{ownerId}") + public ResponseEntity getOwnerAllWaiting( + @PathVariable("ownerId") Long ownerId) { + OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(ownerId); + return ResponseEntity.ok(response); + } +} From 7afb52a037d9e50860a68e9c4887e5f961029973 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:30:49 +0900 Subject: [PATCH 13/21] =?UTF-8?q?feat:=20owner=20=EC=9B=A8=EC=9D=B4?= =?UTF-8?q?=ED=8C=85=20=EC=A1=B0=ED=9A=8C=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OwnerWaitingControllerTest.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java new file mode 100644 index 00000000..6cdaf1c8 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -0,0 +1,120 @@ +package com.prgrms.catchtable.waiting.controller; + +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.prgrms.catchtable.common.base.BaseIntegrationTest; +import com.prgrms.catchtable.member.MemberFixture; +import com.prgrms.catchtable.member.domain.Member; +import com.prgrms.catchtable.member.repository.MemberRepository; +import com.prgrms.catchtable.owner.domain.Owner; +import com.prgrms.catchtable.owner.fixture.OwnerFixture; +import com.prgrms.catchtable.owner.repository.OwnerRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.fixture.ShopFixture; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.waiting.domain.Waiting; +import com.prgrms.catchtable.waiting.repository.WaitingRepository; +import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; +import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; + +class OwnerWaitingControllerTest extends BaseIntegrationTest { + @Autowired + private MemberRepository memberRepository; + @Autowired + private WaitingRepository waitingRepository; + + @Autowired + private OwnerRepository ownerRepository; + + @Autowired + private WaitingLineRepository waitingLineRepository; + @Autowired + private ShopRepository shopRepository; + @Autowired + private StringRedisTemplate redisTemplate; + + private Member member1, member2, member3; + private Shop shop; + private Owner owner; + private Waiting waiting1, waiting2, waiting3; + private List waitings; + + + @BeforeEach + void setUp() { + member1 = MemberFixture.member("test1@naver.com"); + member2 = MemberFixture.member("test2@naver.com"); + member3 = MemberFixture.member("test3@naver.com"); + memberRepository.saveAll(List.of(member1, member2, member3)); + + shop = ShopFixture.shopWith24(); + shopRepository.save(shop); + + owner = OwnerFixture.getOwner(shop); + ownerRepository.save(owner); + + waiting1 = Waiting.builder() + .member(member1) + .shop(shop) + .waitingNumber(1) + .peopleCount(2) + .build(); + waiting2 = Waiting.builder() + .member(member2) + .shop(shop) + .waitingNumber(2) + .peopleCount(2) + .build(); + + waiting3 = Waiting.builder() + .member(member3) + .shop(shop) + .waitingNumber(3) + .peopleCount(2) + .build(); + + waitings = waitingRepository.saveAll(List.of(waiting1, waiting2, waiting3)); + waitingLineRepository.save(shop.getId(), waiting1.getId()); + waitingLineRepository.save(shop.getId(), waiting2.getId()); + waitingLineRepository.save(shop.getId(), waiting3.getId()); + } + + @AfterEach + void clear() { + redisTemplate.delete("s" + shop.getId()); + memberRepository.deleteAll(); + shopRepository.deleteAll(); + ownerRepository.deleteAll(); + waitingRepository.deleteAll(); + } + + @DisplayName("웨이팅 조회 API를 호출할 수 있다.") + @Test + void getWaiting() throws Exception { + //when, then + mockMvc.perform(get("/owner/waitings/{ownerId}", owner.getId()) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.shopWaitings", hasSize(3))) + .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].waitingNumber").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].rank").value(1)) + .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].waitingNumber").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].rank").value(2)) + .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(2)) + ; + } + +} \ No newline at end of file From f18dbdcb156edd9d23fb6e6531c722f7847bd187 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 13:31:38 +0900 Subject: [PATCH 14/21] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/controller/MemberWaitingController.java | 9 ++++++--- .../prgrms/catchtable/waiting/dto/WaitingMapper.java | 10 +++++----- .../dto/response/OwnerWaitingListResponse.java | 6 ++++-- .../waiting/dto/response/OwnerWaitingResponse.java | 6 ++++-- .../waitingline/RedisWaitingLineRepository.java | 2 +- .../waiting/service/OwnerWaitingService.java | 1 - .../prgrms/catchtable/owner/fixture/OwnerFixture.java | 11 +++++------ .../controller/OwnerWaitingControllerTest.java | 1 + .../catchtable/waiting/fixture/WaitingFixture.java | 6 ++---- .../waiting/repository/WaitingRepositoryTest.java | 2 +- .../waiting/service/OwnerWaitingServiceTest.java | 3 ++- 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java index 6a0e32a1..dac21df7 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java +++ b/src/main/java/com/prgrms/catchtable/waiting/controller/MemberWaitingController.java @@ -26,7 +26,8 @@ public class MemberWaitingController { public ResponseEntity createWaiting(@PathVariable("shopId") Long shopId, @PathVariable("memberId") Long memberId, @Valid @RequestBody CreateWaitingRequest request) { - MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, request); + MemberWaitingResponse response = memberWaitingService.createWaiting(shopId, memberId, + request); return ResponseEntity.ok(response); } @@ -38,13 +39,15 @@ public ResponseEntity postponeWaiting( } @DeleteMapping("/{memberId}") - public ResponseEntity cancelWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity cancelWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.cancelWaiting(memberId); return ResponseEntity.ok(response); } @GetMapping("/{memberId}") - public ResponseEntity getWaiting(@PathVariable("memberId") Long memberId) { + public ResponseEntity getWaiting( + @PathVariable("memberId") Long memberId) { MemberWaitingResponse response = memberWaitingService.getWaiting(memberId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java index 52416bf7..75c0e134 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/WaitingMapper.java @@ -40,7 +40,7 @@ public static MemberWaitingResponse toWaitingResponse(Waiting waiting, Long rank .build(); } - public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank){ + public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long rank) { return OwnerWaitingResponse.builder() .waitingId(waiting.getId()) .waitingNumber(waiting.getWaitingNumber()) @@ -49,11 +49,11 @@ public static OwnerWaitingResponse toOwnerWaitingResponse(Waiting waiting, Long .build(); } - public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings){ - long rank=1L; + public static OwnerWaitingListResponse toOwnerWaitingListResponse(List waitings) { + long rank = 1L; List list = new ArrayList<>(); - for (Waiting waiting : waitings){ - list.add(toOwnerWaitingResponse(waiting,rank++)); + for (Waiting waiting : waitings) { + list.add(toOwnerWaitingResponse(waiting, rank++)); } return new OwnerWaitingListResponse(list); } diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java index 70af4cb2..d02d6e81 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingListResponse.java @@ -4,6 +4,8 @@ import lombok.Builder; @Builder -public record OwnerWaitingListResponse ( +public record OwnerWaitingListResponse( List shopWaitings -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java index 763236bb..e3c04197 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java +++ b/src/main/java/com/prgrms/catchtable/waiting/dto/response/OwnerWaitingResponse.java @@ -3,9 +3,11 @@ import lombok.Builder; @Builder -public record OwnerWaitingResponse ( +public record OwnerWaitingResponse( Long waitingId, int waitingNumber, Long rank, int peopleCount -){} +) { + +} diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 92d7b09a..2a936994 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -43,7 +43,7 @@ public Object execute(RedisOperations operations) }); } - public List getShopWaitingIdsInOrder(Long shopId){ + public List getShopWaitingIdsInOrder(Long shopId) { List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); if (stringList == null) { throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); diff --git a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java index 00681ac5..d99c5300 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java +++ b/src/main/java/com/prgrms/catchtable/waiting/service/OwnerWaitingService.java @@ -9,7 +9,6 @@ import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; import com.prgrms.catchtable.waiting.repository.WaitingRepository; -import com.prgrms.catchtable.waiting.repository.waitingline.RedisWaitingLineRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java index 570b7904..bc360e20 100644 --- a/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java +++ b/src/test/java/com/prgrms/catchtable/owner/fixture/OwnerFixture.java @@ -1,7 +1,8 @@ package com.prgrms.catchtable.owner.fixture; +import static com.prgrms.catchtable.member.domain.Gender.MALE; + import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.member.domain.Gender; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.dto.request.JoinOwnerRequest; import com.prgrms.catchtable.owner.dto.request.LoginOwnerRequest; @@ -9,8 +10,6 @@ import java.time.LocalDate; import org.springframework.test.util.ReflectionTestUtils; -import static com.prgrms.catchtable.member.domain.Gender.MALE; - public class OwnerFixture { @@ -29,7 +28,7 @@ public static Owner getOwner(String email, String password) { return owner; } - public static Owner getOwner(Shop shop){ + public static Owner getOwner(Shop shop) { Owner owner = Owner.builder() .name("ownerA") .email("email") @@ -43,7 +42,7 @@ public static Owner getOwner(Shop shop){ return owner; } - public static JoinOwnerRequest getJoinOwnerRequest(String email, String password){ + public static JoinOwnerRequest getJoinOwnerRequest(String email, String password) { return JoinOwnerRequest.builder() .name("ownerA") .email(email) @@ -54,7 +53,7 @@ public static JoinOwnerRequest getJoinOwnerRequest(String email, String password .build(); } - public static LoginOwnerRequest getLoginOwnerRequest(String email, String password){ + public static LoginOwnerRequest getLoginOwnerRequest(String email, String password) { return LoginOwnerRequest.builder() .email(email) .password(password) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index 6cdaf1c8..c52a55a3 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -28,6 +28,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; class OwnerWaitingControllerTest extends BaseIntegrationTest { + @Autowired private MemberRepository memberRepository; @Autowired diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index 2f888593..b663c2c6 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,12 +1,10 @@ package com.prgrms.catchtable.waiting.fixture; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.*; +import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import com.prgrms.catchtable.waiting.domain.WaitingStatus; -import java.time.LocalDateTime; import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -22,7 +20,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - ReflectionTestUtils.setField(waiting, "status", COMPLETED) ; + ReflectionTestUtils.setField(waiting, "status", COMPLETED); return waiting; } } \ No newline at end of file diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java index 0e45655b..91d68de5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/WaitingRepositoryTest.java @@ -81,7 +81,7 @@ void countByShopAndCreatedAtBetween() { @DisplayName("멤버의 아이디 리스트로 Waiting을 조회 가능하다.") @Test - void findByIdsWithMember(){ + void findByIdsWithMember() { Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); Waiting waiting3 = WaitingFixture.waiting(member3, shop, 3); diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 76d17a79..49ee9e9c 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -48,7 +48,8 @@ void getOwnerAllWaiting() { given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); - given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn(waitingIds); + given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( + waitingIds); given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); //when From c2eb81e7c45faa7a87cbb0e772d80b9a685be37e Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 14:00:56 +0900 Subject: [PATCH 15/21] =?UTF-8?q?fix=20:=20ci=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=A4=ED=8C=A8=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OwnerWaitingControllerTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java index c52a55a3..a006ccde 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/controller/OwnerWaitingControllerTest.java @@ -107,14 +107,16 @@ void getWaiting() throws Exception { .contentType(APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.shopWaitings", hasSize(3))) - .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].waitingNumber").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].rank").value(1)) - .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].waitingNumber").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].rank").value(2)) - .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(2)) + .andExpect(jsonPath("$.shopWaitings[0].waitingId").value(waiting1.getId())) + .andExpect( + jsonPath("$.shopWaitings[0].waitingNumber").value(waiting1.getWaitingNumber())) + .andExpect(jsonPath("$.shopWaitings[0].rank").value(1L)) + .andExpect(jsonPath("$.shopWaitings[0].peopleCount").value(waiting1.getPeopleCount())) + .andExpect(jsonPath("$.shopWaitings[1].waitingId").value(waiting2.getId())) + .andExpect( + jsonPath("$.shopWaitings[1].waitingNumber").value(waiting2.getWaitingNumber())) + .andExpect(jsonPath("$.shopWaitings[1].rank").value(2L)) + .andExpect(jsonPath("$.shopWaitings[1].peopleCount").value(waiting2.getPeopleCount())) ; } From 5cdfadc45f3d9f6081de69b03115028d7c6454d8 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:35:48 +0900 Subject: [PATCH 16/21] =?UTF-8?q?feat=20:=20basicWaitingLine=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C=EC=A7=81=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20=EA=B2=80=EC=A6=9D=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/waitingline/BasicWaitingLineRepositoryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java index ac7f77cd..5be42490 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/repository/waitingline/BasicWaitingLineRepositoryTest.java @@ -124,8 +124,9 @@ void getShopWaitingIdOrder() { //when List waitingIds = repository.getShopWaitingIdsInOrder(shopId); //then - System.out.println("waitingIds = " + waitingIds); assertThat(waitingIds.get(0)).isEqualTo(1L); + assertThat(waitingIds.get(1)).isEqualTo(2L); + assertThat(waitingIds.get(2)).isEqualTo(3L); } } \ No newline at end of file From ec30c7ce491b0a3377891ffb52adc0d9b2aa2e89 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:47:14 +0900 Subject: [PATCH 17/21] =?UTF-8?q?refactor=20:=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=95=A8=EC=88=98=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EA=B2=80=EC=A6=9D=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/waiting/domain/Waiting.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java index e953c7bc..f9ea780b 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java +++ b/src/main/java/com/prgrms/catchtable/waiting/domain/Waiting.java @@ -1,10 +1,8 @@ package com.prgrms.catchtable.waiting.domain; -import static com.prgrms.catchtable.common.exception.ErrorCode.CAN_NOT_COMPLETE_WAITING; import static com.prgrms.catchtable.common.exception.ErrorCode.POSTPONE_REMAINING_CNT_0; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.CANCELED; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.NO_SHOW; import static com.prgrms.catchtable.waiting.domain.WaitingStatus.PROGRESS; import static jakarta.persistence.ConstraintMode.NO_CONSTRAINT; import static jakarta.persistence.EnumType.STRING; @@ -77,14 +75,10 @@ public void decreasePostponeRemainingCount() { remainingPostponeCount--; } - public void completeWaiting() { - if (status == NO_SHOW || status == CANCELED) { - throw new BadRequestCustomException(CAN_NOT_COMPLETE_WAITING); - } + public void changeStatusCompleted() { status = COMPLETED; } - public void changeStatusCanceled() { status = CANCELED; } From 08da5a3697c6d277c369816235ae6412a4fbbf34 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 16:51:37 +0900 Subject: [PATCH 18/21] =?UTF-8?q?refactor=20:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20fixture=20reflectionUtil=20=EB=8C=80=EC=8B=A0=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=ED=95=A8=EC=88=98=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/waiting/fixture/WaitingFixture.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java index b663c2c6..399bf936 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java +++ b/src/test/java/com/prgrms/catchtable/waiting/fixture/WaitingFixture.java @@ -1,11 +1,8 @@ package com.prgrms.catchtable.waiting.fixture; -import static com.prgrms.catchtable.waiting.domain.WaitingStatus.COMPLETED; - import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; -import org.springframework.test.util.ReflectionTestUtils; public class WaitingFixture { @@ -20,7 +17,7 @@ public static Waiting waiting(Member member, Shop shop, int waitingNumber) { public static Waiting completedWaiting(Member member, Shop shop, int waitingNumber) { Waiting waiting = waiting(member, shop, waitingNumber); - ReflectionTestUtils.setField(waiting, "status", COMPLETED); + waiting.changeStatusCompleted(); return waiting; } } \ No newline at end of file From 5344cf7db3a03a100d3dabc756eda84cec540ac9 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:05:31 +0900 Subject: [PATCH 19/21] =?UTF-8?q?feat=20:=20owner=20waiting=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OwnerWaitingServiceTest.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index 49ee9e9c..be5e82b5 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -5,11 +5,13 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; +import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.owner.domain.Owner; import com.prgrms.catchtable.owner.repository.OwnerRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.waiting.domain.Waiting; import com.prgrms.catchtable.waiting.dto.response.OwnerWaitingListResponse; +import com.prgrms.catchtable.waiting.fixture.WaitingFixture; import com.prgrms.catchtable.waiting.repository.WaitingRepository; import com.prgrms.catchtable.waiting.repository.waitingline.WaitingLineRepository; import java.util.List; @@ -40,21 +42,31 @@ class OwnerWaitingServiceTest { @Test void getOwnerAllWaiting() { //given - List waitingIds = List.of(1L); + List waitingIds = List.of(1L,2L); + Member member1 = mock(Member.class); + Member member2 = mock(Member.class); Owner owner = mock(Owner.class); Shop shop = mock(Shop.class); - Waiting waiting = mock(Waiting.class); + Waiting waiting1 = WaitingFixture.waiting(member1, shop, 1); + Waiting waiting2 = WaitingFixture.waiting(member2, shop, 2); given(ownerRepository.findById(1L)).willReturn(Optional.of(owner)); given(owner.getShop()).willReturn(shop); given(shop.getId()).willReturn(1L); given(waitingLineRepository.getShopWaitingIdsInOrder(any(Long.class))).willReturn( waitingIds); - given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting)); + given(waitingRepository.findByIds(waitingIds)).willReturn(List.of(waiting1, waiting2)); //when OwnerWaitingListResponse response = ownerWaitingService.getOwnerAllWaiting(1L); + //then - assertThat(response).isNotNull(); + assertThat(response.shopWaitings()).hasSize(2); + + assertThat(response.shopWaitings().get(0).waitingId()).isEqualTo(waiting1.getId()); + assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo(waiting1.getWaitingNumber()); + + assertThat(response.shopWaitings().get(1).waitingId()).isEqualTo(waiting2.getId()); + assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo(waiting2.getWaitingNumber()); } } \ No newline at end of file From c7477428cdba1f4ad5824bdd39209c2791cfbef5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:42:05 +0900 Subject: [PATCH 20/21] =?UTF-8?q?refactor=20:=20redis=20rank=20=EC=98=A4?= =?UTF-8?q?=EB=A6=84=EC=B0=A8=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=B4=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waitingline/RedisWaitingLineRepository.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java index 2a936994..e1124b5e 100644 --- a/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java +++ b/src/main/java/com/prgrms/catchtable/waiting/repository/waitingline/RedisWaitingLineRepository.java @@ -44,15 +44,14 @@ public Object execute(RedisOperations operations) } public List getShopWaitingIdsInOrder(Long shopId) { - List stringList = redisTemplate.opsForList().range("s" + shopId, 0, -1); - if (stringList == null) { + List waitingIds = redisTemplate.opsForList().range("s" + shopId, 0, -1); + if (waitingIds == null) { throw new BadRequestCustomException(WAITING_DOES_NOT_EXIST); } - List longList = new ArrayList<>(stringList.stream() + Collections.reverse(waitingIds); + return new ArrayList<>(waitingIds.stream() .map(Long::parseLong) .toList()); - Collections.reverse(longList); - return longList; } public void entry(Long shopId, Long waitingId) { From 0939180795ddd69c849b54d2bd60b31d3e0c69a5 Mon Sep 17 00:00:00 2001 From: hs12 Date: Mon, 8 Jan 2024 17:43:11 +0900 Subject: [PATCH 21/21] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8F=AC=EB=A9=A7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waiting/service/OwnerWaitingServiceTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java index be5e82b5..d2ce0887 100644 --- a/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/waiting/service/OwnerWaitingServiceTest.java @@ -42,7 +42,7 @@ class OwnerWaitingServiceTest { @Test void getOwnerAllWaiting() { //given - List waitingIds = List.of(1L,2L); + List waitingIds = List.of(1L, 2L); Member member1 = mock(Member.class); Member member2 = mock(Member.class); Owner owner = mock(Owner.class); @@ -64,9 +64,11 @@ void getOwnerAllWaiting() { assertThat(response.shopWaitings()).hasSize(2); assertThat(response.shopWaitings().get(0).waitingId()).isEqualTo(waiting1.getId()); - assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo(waiting1.getWaitingNumber()); + assertThat(response.shopWaitings().get(0).waitingNumber()).isEqualTo( + waiting1.getWaitingNumber()); assertThat(response.shopWaitings().get(1).waitingId()).isEqualTo(waiting2.getId()); - assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo(waiting2.getWaitingNumber()); + assertThat(response.shopWaitings().get(1).waitingNumber()).isEqualTo( + waiting2.getWaitingNumber()); } } \ No newline at end of file