From b5865453a25700da234267e5bc4c551eeb0b4542 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:08:53 +0900 Subject: [PATCH 01/46] =?UTF-8?q?feat=20:=20ReservationRepository=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java new file mode 100644 index 00000000..e4e2642a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.reservation.repository; + +import com.prgrms.catchtable.reservation.domain.Reservation; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReservationRepository extends JpaRepository { + +} From f3c8fc4ca3449ae051bb10332df55f1cd678cee7 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:09:50 +0900 Subject: [PATCH 02/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=84=A0=EC=A0=90?= =?UTF-8?q?=EA=B6=8C=20=EC=97=AC=EB=B6=80=20=ED=95=84=EB=93=9C=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 --- .../prgrms/catchtable/reservation/domain/ReservationTime.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 60ee4924..f579f848 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -34,6 +34,9 @@ public class ReservationTime { @Column(name = "is_occupied") private boolean isOccupied; + @Column(name = "is_pre_occupied") + private boolean isPreOccupied; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; From b40b4195c0a40e6856bb9c730978d1da5f74e001 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 02:12:03 +0900 Subject: [PATCH 03/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20api=20=EA=B4=80=EB=A0=A8=20dto?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/CreateResercationRequest.java | 7 +++++++ .../dto/response/CreateReservationResponse.java | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java new file mode 100644 index 00000000..2d759d2b --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.request; + +import java.time.LocalDateTime; + +public record CreateResercationRequest(LocalDateTime date, int peopleCount) { + +} diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java new file mode 100644 index 00000000..f5da7f55 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import java.time.LocalDateTime; + +public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, int peopleCount) { + +} From c56bce6dacafb47bcbf25fc2feef4624a178bd56 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 03:05:32 +0900 Subject: [PATCH 04/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20api=20=ED=8B=80=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ReservationController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java new file mode 100644 index 00000000..e6b125ab --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -0,0 +1,25 @@ +package com.prgrms.catchtable.reservation.controller; + +import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +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; + +@RestController +@RequestMapping("/reservations") +@RequiredArgsConstructor +public class ReservationController { + + private final ReservationService reservationService; + + @GetMapping("/{shopId}") + public CreateReservationResponse createReservationResponse( + @PathVariable("shopId") Long shopId, + CreateResercationRequest request) { + return null; + } +} From 67325fdc078f96eacb269b97e52f3e7e66b4e659 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Sat, 23 Dec 2023 03:05:46 +0900 Subject: [PATCH 05/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EC=84=A0=EC=A0=90=20Service=20=ED=8B=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java new file mode 100644 index 00000000..a99fe869 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -0,0 +1,37 @@ +package com.prgrms.catchtable.reservation.service; + +import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +import java.time.LocalDateTime; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ReservationService { + + private final ReservationRepository reservationRepository; + private final ShopRepository shopRepository; + @Transactional + public CreateReservationResponse createReservation(Long shopId, CreateResercationRequest request) { + LocalDateTime requestedReservationTime = request.date(); + int requestedPeopleCount = request.peopleCount(); + + Shop shop = shopRepository.findById(shopId).orElseThrow(); + /** + * 해당 shop의 예약하려는 날짜와 시간이 비어있는 지 확인하는 로직 + * reservationTime = select rt from Shop s join ReservationTime rt where rt.time = :time; + * reservationTime.isOccupied == true? -> 이미 예약되어있다는 예외 발생 + * reservationTime.isPreOccupied == true? -> 타인이 예약중이라는 예외 발생 + * 선점권 스케줄러 실행 + */ + + // 퍼사드를 따로 빼서 이 프로세스가 끝나면 비동기 이벤트가 수행되게 해보자 + // 퍼사드에서 이 서비스 실행 로직 , 그리고 이벤트 발행 + return new CreateReservationResponse(shop.getName(), "member", requestedReservationTime, requestedPeopleCount); + } +} From c34397d7da851e541a987f9ac4a21bf06c8e1b4f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:20:40 +0900 Subject: [PATCH 06/46] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EC=9A=94=EC=B2=AD=20dto=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ateResercationRequest.java => CreateReservationRequest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/prgrms/catchtable/reservation/dto/request/{CreateResercationRequest.java => CreateReservationRequest.java} (62%) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java similarity index 62% rename from src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java rename to src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 2d759d2b..2de0a9cb 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateResercationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -2,6 +2,6 @@ import java.time.LocalDateTime; -public record CreateResercationRequest(LocalDateTime date, int peopleCount) { +public record CreateReservationRequest(LocalDateTime date, int peopleCount) { } From bbf3e0e368940c09a25675810f420e384e971e2e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:21:28 +0900 Subject: [PATCH 07/46] =?UTF-8?q?feat=20:=20Reservation=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EB=A9=94=EC=84=9C=EB=93=9C=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 --- .../prgrms/catchtable/reservation/domain/Reservation.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index f4e47763..ed02024b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -56,4 +56,12 @@ public Reservation(ReservationStatus status, int peopleCount) { this.status = status; this.peopleCount = peopleCount; } + + public void insertReservvationTime(ReservationTime reservationTime){ + this.time = reservationTime; + } + + public void insertShop(Shop shop) { + this.shop = shop; + } } From edb3ab913519a7a1e8038a03b93fc7cd739c6772 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:22:45 +0900 Subject: [PATCH 08/46] =?UTF-8?q?feat=20:=20ReservaitonTime=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=EC=97=AC=EB=B6=80,=20=EC=84=A0=EC=A0=90=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=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 --- .../catchtable/reservation/domain/ReservationTime.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index f579f848..98022d4d 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -46,4 +46,12 @@ public ReservationTime(LocalDateTime time) { this.time = time; this.isOccupied = false; } + + public void reverseOccupied(){ + this.isOccupied = !this.isOccupied; + } + + public void reversePreOccupied(){ + this.isPreOccupied = !this.isPreOccupied; + } } From e4141009907ec9b1153dd2322b0d09954bbf3678 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:25:06 +0900 Subject: [PATCH 09/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EA=B6=8C=20=EC=B7=A8=EB=93=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?1=EC=B0=A8=20=EA=B5=AC=ED=98=84=20-=20=EC=B6=94=ED=9B=84?= =?UTF-8?q?=EC=97=90=20Oauth=EB=A5=BC=20=ED=86=B5=ED=95=B4=20member=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81=20-=20=ED=98=84=EC=9E=AC=EB=8A=94?= =?UTF-8?q?=20=EC=98=88=EC=A0=9C=20=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=9D=84=20=EC=A7=81=EC=A0=91=20=EC=83=9D=EC=84=B1,=20?= =?UTF-8?q?=EC=B6=94=ED=9B=84=EC=97=90=20shop=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=A1=B0=ED=9A=8C=ED=95=B4?= =?UTF-8?q?=EC=95=BC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index a99fe869..23338922 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,7 +1,11 @@ package com.prgrms.catchtable.reservation.service; -import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; -import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; + +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.shop.domain.Shop; import com.prgrms.catchtable.shop.repository.ShopRepository; @@ -16,22 +20,35 @@ public class ReservationService { private final ReservationRepository reservationRepository; private final ShopRepository shopRepository; + @Transactional - public CreateReservationResponse createReservation(Long shopId, CreateResercationRequest request) { + public ValidateReservationResponse validateReservationIsPossible(Long shopId, + CreateReservationRequest request) { LocalDateTime requestedReservationTime = request.date(); int requestedPeopleCount = request.peopleCount(); Shop shop = shopRepository.findById(shopId).orElseThrow(); - /** - * 해당 shop의 예약하려는 날짜와 시간이 비어있는 지 확인하는 로직 - * reservationTime = select rt from Shop s join ReservationTime rt where rt.time = :time; - * reservationTime.isOccupied == true? -> 이미 예약되어있다는 예외 발생 - * reservationTime.isPreOccupied == true? -> 타인이 예약중이라는 예외 발생 - * 선점권 스케줄러 실행 - */ - - // 퍼사드를 따로 빼서 이 프로세스가 끝나면 비동기 이벤트가 수행되게 해보자 - // 퍼사드에서 이 서비스 실행 로직 , 그리고 이벤트 발행 - return new CreateReservationResponse(shop.getName(), "member", requestedReservationTime, requestedPeopleCount); + //예제 데이터 + ReservationTime reservationTime = ReservationTime.builder() + .time(request.date()) + .build(); + Reservation reservation = Reservation.builder() + .status(COMPLETED) + .peopleCount(request.peopleCount()) + .build(); + + if (reservationTime.isPreOccupied()) { + throw new RuntimeException("타인에게 선점권이 있음"); + } + if (reservationTime.isOccupied()) { + throw new RuntimeException("이미 예약된 시간임"); + } + + reservation.insertReservvationTime(reservationTime); + reservation.insertShop(shop); + + Reservation savedReservation = reservationRepository.save(reservation); + + return new ValidateReservationResponse(savedReservation.getShop().getName(), savedReservation.getTime()); } } From daa8856cb475bdfa26b59df104c1cf87fd64b5b5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:26:49 +0900 Subject: [PATCH 10/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=ED=95=98=EB=8A=94=20=EB=B9=84=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationAsync.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java new file mode 100644 index 00000000..a6551170 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -0,0 +1,29 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +@Component +@RequiredArgsConstructor +public class ReservationAsync { + + @Async + @Transactional(propagation = REQUIRES_NEW) + public void setPreOcuppied(ReservationTime reservationTime) { + reservationTime.reversePreOccupied(); + + try { + Thread.sleep(5_000); + } catch (InterruptedException exception) { + exception.printStackTrace(); + } + + reservationTime.reversePreOccupied(); + } + +} From 6a8474dea21ae0615029f9e4f9bee8e0758b38d6 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:27:52 +0900 Subject: [PATCH 11/46] =?UTF-8?q?feat=20:=20Test=20data=EC=9A=A9=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC=ED=98=84(=EC=98=88?= =?UTF-8?q?=EC=95=BD,=20=EB=A7=A4=EC=9E=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reservation/ReservationData.java | 28 +++++++++++++++++++ .../catchtable/common/data/shop/ShopData.java | 20 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java create mode 100644 src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java new file mode 100644 index 00000000..f56faa8f --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -0,0 +1,28 @@ +package com.prgrms.catchtable.common.data.reservation; + +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; + +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import java.time.LocalDateTime; + +public class ReservationData { + public static Reservation getReservation(){ + return Reservation.builder() + .status(COMPLETED) + .peopleCount(4) + .build(); + } + public static ReservationTime getReservationTime(){ + return ReservationTime.builder() + .time(LocalDateTime.of(2023, 12, 31, 19, 30)) + .build(); + } + + public static CreateReservationRequest getCreateReservationRequest(){ + return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); + } + +} diff --git a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java new file mode 100644 index 00000000..a7a33ad3 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java @@ -0,0 +1,20 @@ +package com.prgrms.catchtable.common.data.shop; + +import static com.prgrms.catchtable.shop.domain.Category.*; + +import com.prgrms.catchtable.shop.domain.Address; +import com.prgrms.catchtable.shop.domain.Category; +import com.prgrms.catchtable.shop.domain.Shop; +import java.math.BigDecimal; + +public class ShopData { + public static Shop getShop(){ + return Shop.builder() + .name("shopA") + .rating(BigDecimal.valueOf(5L)) + .category(JAPANESE_FOOD) + .address(Address.builder().build()) + .capacity(30) + .build(); + } +} From 125769f2e493d0305787872f4cb483ad9f0bb15f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:28:29 +0900 Subject: [PATCH 12/46] =?UTF-8?q?feat=20:=20ReservationService=20=EC=98=88?= =?UTF-8?q?=EC=95=BD=20=EC=84=A0=EC=A0=90=20=EC=97=AC=EB=B6=80=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationServiceTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java new file mode 100644 index 00000000..6ec9ca3d --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -0,0 +1,57 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.common.data.shop.ShopData; +import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.shop.repository.ShopRepository; +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; +import org.springframework.test.util.ReflectionTestUtils; + +@ExtendWith(MockitoExtension.class) +class ReservationServiceTest { + + @Mock + private ReservationRepository reservationRepository; + @Mock + private ShopRepository shopRepository; + @InjectMocks + private ReservationService reservationService; + + @Test + @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") + void validateReservation() { + Reservation reservation = ReservationData.getReservation(); + CreateReservationRequest createReservationRequest = ReservationData.getCreateReservationRequest(); + Shop shop = ShopData.getShop(); + + reservation.insertShop(shop); + reservation.insertReservvationTime(ReservationData.getReservationTime()); + + ReflectionTestUtils.setField(shop, "id", 1L); + + when(shopRepository.findById(any(Long.class))).thenReturn(Optional.of(shop)); + when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + + ValidateReservationResponse response = reservationService.validateReservationIsPossible( + shop.getId(), createReservationRequest); + assertAll( + () -> assertThat(response.reservationTime().getTime()).isEqualTo(createReservationRequest.date()), + () -> assertThat(response.shopName()).isEqualTo(shop.getName()) + ); + } +} \ No newline at end of file From bccd4f5c11ee66033711adccf9d7b6d422a2e64a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:28:43 +0900 Subject: [PATCH 13/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=ED=95=98=EB=8A=94=20=EB=B9=84=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java new file mode 100644 index 00000000..c2d1b7c4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -0,0 +1,42 @@ +package com.prgrms.catchtable.reservation.service; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.repository.ReservationRepository; +import org.assertj.core.api.Assertions; +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; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ReservationAsyncTest { + + @Mock + private ReservationRepository reservationRepository; + @InjectMocks + private ReservationAsync reservationAsync; + + @Test + @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") + void preOccupiedAsync(){ + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationAsync.setPreOcuppied(reservationTime); + + assertThat(reservationTime.isPreOccupied()).isTrue(); + + try { + Thread.sleep(6_000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + assertThat(reservationTime.isPreOccupied()).isFalse(); + } +} \ No newline at end of file From 78e0c338dcf78ac75f8d24302b012f0ed90846b5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:30:22 +0900 Subject: [PATCH 14/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=ED=8D=BC?= =?UTF-8?q?=EC=82=AC=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B0=9B=EB=8A=94=20=EC=9D=91=EB=8B=B5=20dto=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ValidateReservationResponse.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java new file mode 100644 index 00000000..ee0e91d1 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -0,0 +1,7 @@ +package com.prgrms.catchtable.reservation.dto.response; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; + +public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { + +} From ac5d2a7478764d26e2172bbceb7f74df558118a2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:30:33 +0900 Subject: [PATCH 15/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=ED=8D=BC?= =?UTF-8?q?=EC=82=AC=EB=93=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/facade/ReservationFacade.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java new file mode 100644 index 00000000..84cc2490 --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -0,0 +1,33 @@ +package com.prgrms.catchtable.facade; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationAsync; +import com.prgrms.catchtable.reservation.service.ReservationService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReservationFacade { + + private final ReservationService reservationService; + private final ReservationAsync reservationAsync; + + public CreateReservationResponse createReservation(Long shopId, + CreateReservationRequest request) { + ValidateReservationResponse validateReservationResponse = reservationService.validateReservationIsPossible( + shopId, + request); + + String shopName = validateReservationResponse.shopName(); + ReservationTime reservationTime = validateReservationResponse.reservationTime(); + + reservationAsync.setPreOcuppied(reservationTime); + + return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), request.peopleCount()); + } + +} From 651291789d51b454cfd6ab20263c1eab76c81679 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:31:44 +0900 Subject: [PATCH 16/46] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20api?= =?UTF-8?q?=20=EC=98=88=EC=95=BD=20=EB=93=B1=EB=A1=9D=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=20dto=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/controller/ReservationController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index e6b125ab..3cff7823 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.controller; -import com.prgrms.catchtable.reservation.dto.request.CreateResercationRequest; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -19,7 +19,7 @@ public class ReservationController { @GetMapping("/{shopId}") public CreateReservationResponse createReservationResponse( @PathVariable("shopId") Long shopId, - CreateResercationRequest request) { + CreateReservationRequest request) { return null; } } From b4c47f945468ab0d986ad007682901e8b492de13 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:33:25 +0900 Subject: [PATCH 17/46] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/prgrms/catchtable/facade/ReservationFacade.java | 3 ++- .../prgrms/catchtable/reservation/domain/Reservation.java | 2 +- .../catchtable/reservation/domain/ReservationTime.java | 4 ++-- .../reservation/dto/response/CreateReservationResponse.java | 3 ++- .../catchtable/reservation/service/ReservationService.java | 5 +++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index 84cc2490..8cf1f723 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -27,7 +27,8 @@ public CreateReservationResponse createReservation(Long shopId, reservationAsync.setPreOcuppied(reservationTime); - return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), request.peopleCount()); + return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), + request.peopleCount()); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index ed02024b..ddb26f2f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -57,7 +57,7 @@ public Reservation(ReservationStatus status, int peopleCount) { this.peopleCount = peopleCount; } - public void insertReservvationTime(ReservationTime reservationTime){ + public void insertReservvationTime(ReservationTime reservationTime) { this.time = reservationTime; } diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 98022d4d..d11f2f8a 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -47,11 +47,11 @@ public ReservationTime(LocalDateTime time) { this.isOccupied = false; } - public void reverseOccupied(){ + public void reverseOccupied() { this.isOccupied = !this.isOccupied; } - public void reversePreOccupied(){ + public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index f5da7f55..1730ec96 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; -public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, int peopleCount) { +public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, + int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 23338922..75f8668b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.*; +import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; @@ -49,6 +49,7 @@ public ValidateReservationResponse validateReservationIsPossible(Long shopId, Reservation savedReservation = reservationRepository.save(reservation); - return new ValidateReservationResponse(savedReservation.getShop().getName(), savedReservation.getTime()); + return new ValidateReservationResponse(savedReservation.getShop().getName(), + savedReservation.getTime()); } } From 321bacd5d1150e90aef79215b72e225cdbe0f9df Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 01:59:46 +0900 Subject: [PATCH 18/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=97=AC?= =?UTF-8?q?=EB=B6=80,=20=EC=84=A0=EC=A0=90=EC=97=AC=EB=B6=80=20=EA=B0=92?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/ReservationTimeTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java new file mode 100644 index 00000000..abade0a4 --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -0,0 +1,28 @@ +package com.prgrms.catchtable.reservation.domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class ReservationTimeTest { + + @Test + @DisplayName("예약 선점 여부 변경에 성공한다") + void reversePreOccupied() { + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationTime.reversePreOccupied(); + + assertThat(reservationTime.isPreOccupied()).isTrue(); + } + + @Test + @DisplayName("예약 여부 변경에 성공한다.") + void reverseOccupied() { + ReservationTime reservationTime = ReservationData.getReservationTime(); + reservationTime.reverseOccupied(); + + assertThat(reservationTime.isOccupied()).isTrue(); + } +} \ No newline at end of file From 826fb02ea1376f533e7bc51df5f3bcb3376212cd Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 02:00:33 +0900 Subject: [PATCH 19/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=20=EB=B9=84=EB=8F=99=EA=B8=B0=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20SpringbootTest=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java index c2d1b7c4..c0f09353 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -1,33 +1,28 @@ package com.prgrms.catchtable.reservation.service; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; import com.prgrms.catchtable.common.data.reservation.ReservationData; import com.prgrms.catchtable.reservation.domain.ReservationTime; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import org.assertj.core.api.Assertions; 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; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ReservationAsyncTest { - @Mock - private ReservationRepository reservationRepository; - @InjectMocks + @Autowired private ReservationAsync reservationAsync; @Test @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") - void preOccupiedAsync(){ + void preOccupiedAsync() { ReservationTime reservationTime = ReservationData.getReservationTime(); reservationAsync.setPreOcuppied(reservationTime); + reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -36,7 +31,7 @@ void preOccupiedAsync(){ } catch (InterruptedException e) { throw new RuntimeException(e); } - + reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isFalse(); } } \ No newline at end of file From d454045f0867cac153eeb47836fe5d09a343ba99 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Tue, 26 Dec 2023 02:02:23 +0900 Subject: [PATCH 20/46] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/data/reservation/ReservationData.java | 9 +++++---- .../com/prgrms/catchtable/common/data/shop/ShopData.java | 6 +++--- .../reservation/service/ReservationAsyncTest.java | 2 -- .../reservation/service/ReservationServiceTest.java | 3 ++- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index f56faa8f..624f3f10 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -2,26 +2,27 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; -import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import java.time.LocalDateTime; public class ReservationData { - public static Reservation getReservation(){ + + public static Reservation getReservation() { return Reservation.builder() .status(COMPLETED) .peopleCount(4) .build(); } - public static ReservationTime getReservationTime(){ + + public static ReservationTime getReservationTime() { return ReservationTime.builder() .time(LocalDateTime.of(2023, 12, 31, 19, 30)) .build(); } - public static CreateReservationRequest getCreateReservationRequest(){ + public static CreateReservationRequest getCreateReservationRequest() { return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); } diff --git a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java index a7a33ad3..4b71a7d1 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/shop/ShopData.java @@ -1,14 +1,14 @@ package com.prgrms.catchtable.common.data.shop; -import static com.prgrms.catchtable.shop.domain.Category.*; +import static com.prgrms.catchtable.shop.domain.Category.JAPANESE_FOOD; import com.prgrms.catchtable.shop.domain.Address; -import com.prgrms.catchtable.shop.domain.Category; import com.prgrms.catchtable.shop.domain.Shop; import java.math.BigDecimal; public class ShopData { - public static Shop getShop(){ + + public static Shop getShop() { return Shop.builder() .name("shopA") .rating(BigDecimal.valueOf(5L)) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java index c0f09353..4734c7df 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java @@ -6,8 +6,6 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index 6ec9ca3d..a3a64724 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -50,7 +50,8 @@ void validateReservation() { ValidateReservationResponse response = reservationService.validateReservationIsPossible( shop.getId(), createReservationRequest); assertAll( - () -> assertThat(response.reservationTime().getTime()).isEqualTo(createReservationRequest.date()), + () -> assertThat(response.reservationTime().getTime()).isEqualTo( + createReservationRequest.date()), () -> assertThat(response.shopName()).isEqualTo(shop.getName()) ); } From 6308661fa775bde1c12b327cee8d01c97707d9a5 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:42:28 +0900 Subject: [PATCH 21/46] =?UTF-8?q?chore=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=20=EC=9D=98=EC=A1=B4=EC=84=B1=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 --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index 57f64ad1..361994f5 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,8 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' } tasks.named('test') { From 8cd163ba871e8a513e2089256fc516f09dfcc676 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:44:51 +0900 Subject: [PATCH 22/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=20=EC=9A=94=EC=B2=AD=20dto=20=EC=88=98=EC=A0=95=20-?= =?UTF-8?q?=20=EA=B8=B0=EC=A1=B4=20:=20=EC=8B=9C=EA=B0=84,=20=EC=9D=B8?= =?UTF-8?q?=EC=9B=90=20-=20=EB=B3=80=EA=B2=BD=20:=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=95=84=EC=9D=B4=EB=94=94,=20=EC=9D=B8?= =?UTF-8?q?=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/dto/request/CreateReservationRequest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 2de0a9cb..41c3b6a0 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,7 +1,5 @@ package com.prgrms.catchtable.reservation.dto.request; -import java.time.LocalDateTime; - -public record CreateReservationRequest(LocalDateTime date, int peopleCount) { +public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { } From cf1de2d74faf1282cec5d79314a55ceb36f776fb Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:48:22 +0900 Subject: [PATCH 23/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EC=97=90=20=ED=95=84=EC=9A=94=ED=95=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=BD=94=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 --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 876f8b79..45db60e4 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -6,7 +6,11 @@ @Getter @RequiredArgsConstructor public enum ErrorCode { - NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."); + NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."), + IS_PRE_OCCUPIED("이미 타인에게 선점권이 있는 예약시간입니다."), + IS_OCCUPIED("이미 예약된 시간입니다."), + NOT_EXIST_SHOP("존재하지 않는 매장입니다."), + NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); private final String message; } From f831d84b15442b91d5022b19303d5b53cc24e932 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:48:45 +0900 Subject: [PATCH 24/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20-=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84=20=EC=98=81=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=A0=84=EC=9D=B4=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/domain/Reservation.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index ddb26f2f..e9e08d5b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -8,6 +8,7 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -47,18 +48,15 @@ public class Reservation extends BaseEntity { @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - @OneToOne(fetch = LAZY) + @OneToOne(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) - private ReservationTime time; + private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount) { + public Reservation(ReservationStatus status, int peopleCount, ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; - } - - public void insertReservvationTime(ReservationTime reservationTime) { - this.time = reservationTime; + this.reservationTime = reservationTime; } public void insertShop(Shop shop) { From f20aa75c1f3063f320dcab5a28fee0a1f79a51b1 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:49:09 +0900 Subject: [PATCH 25/46] =?UTF-8?q?remove=20:=20ReservationAsync=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationAsyncTest.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java deleted file mode 100644 index 4734c7df..00000000 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationAsyncTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.prgrms.catchtable.reservation.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.prgrms.catchtable.common.data.reservation.ReservationData; -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ReservationAsyncTest { - - @Autowired - private ReservationAsync reservationAsync; - - @Test - @DisplayName("예약 선점을 실행한 후 7분이 지나기 전 후로 선점여부 값이 알맞게 바뀌어야 한다.") - void preOccupiedAsync() { - ReservationTime reservationTime = ReservationData.getReservationTime(); - reservationAsync.setPreOcuppied(reservationTime); - reservationTime.reversePreOccupied(); - - assertThat(reservationTime.isPreOccupied()).isTrue(); - - try { - Thread.sleep(6_000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - reservationTime.reversePreOccupied(); - assertThat(reservationTime.isPreOccupied()).isFalse(); - } -} \ No newline at end of file From 87bf03a7d5fca0b1a74ddbe2c0b92059d8d7edb0 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:50:16 +0900 Subject: [PATCH 26/46] =?UTF-8?q?remove=20:=20ReservationAsync=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EA=B6=8C=20=ED=9A=8D=EB=93=9D=20=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=A4=84=EB=9F=AC=EB=A5=BC=20=ED=86=B5=ED=95=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/service/ReservationAsync.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index a6551170..2d495747 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -1,29 +1,26 @@ package com.prgrms.catchtable.reservation.service; -import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; - import com.prgrms.catchtable.reservation.domain.ReservationTime; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Async; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor +@Slf4j public class ReservationAsync { - @Async - @Transactional(propagation = REQUIRES_NEW) + @Transactional public void setPreOcuppied(ReservationTime reservationTime) { reservationTime.reversePreOccupied(); - try { - Thread.sleep(5_000); - } catch (InterruptedException exception) { - exception.printStackTrace(); - } + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + scheduler.schedule(reservationTime::reversePreOccupied, 10, TimeUnit.SECONDS); - reservationTime.reversePreOccupied(); + scheduler.shutdown(); } - } From f05aea7c7696f925edaa766aec75810eadb5f7d9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:56:17 +0900 Subject: [PATCH 27/46] =?UTF-8?q?remove=20:=20=EC=98=88=EC=95=BD=EC=84=A0?= =?UTF-8?q?=EC=A0=90=20api=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20=EC=9A=94=EC=B2=AD=20dto=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/ReservationController.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java index 3cff7823..8f344697 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java +++ b/src/main/java/com/prgrms/catchtable/reservation/controller/ReservationController.java @@ -1,11 +1,11 @@ package com.prgrms.catchtable.reservation.controller; +import com.prgrms.catchtable.facade.ReservationFacade; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -14,12 +14,11 @@ @RequiredArgsConstructor public class ReservationController { - private final ReservationService reservationService; + private final ReservationFacade reservationFacade; - @GetMapping("/{shopId}") - public CreateReservationResponse createReservationResponse( - @PathVariable("shopId") Long shopId, + @PostMapping + public ResponseEntity createReservationResponse( CreateReservationRequest request) { - return null; + return ResponseEntity.ok(reservationFacade.preOccupyReservation(request)); } } From c0ff8f59c01f0091725c11dbe719d5f99db4ae61 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:58:48 +0900 Subject: [PATCH 28/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=97=AD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ReservationService.java | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index 75f8668b..d3e25e90 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,15 +1,15 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import static com.prgrms.catchtable.common.exception.ErrorCode.IS_PRE_OCCUPIED; +import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; -import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import com.prgrms.catchtable.shop.domain.Shop; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import com.prgrms.catchtable.shop.repository.ShopRepository; -import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,38 +18,17 @@ @RequiredArgsConstructor public class ReservationService { - private final ReservationRepository reservationRepository; - private final ShopRepository shopRepository; + private final ReservationTimeRepository reservationTimeRepository; @Transactional - public ValidateReservationResponse validateReservationIsPossible(Long shopId, - CreateReservationRequest request) { - LocalDateTime requestedReservationTime = request.date(); - int requestedPeopleCount = request.peopleCount(); - - Shop shop = shopRepository.findById(shopId).orElseThrow(); - //예제 데이터 - ReservationTime reservationTime = ReservationTime.builder() - .time(request.date()) - .build(); - Reservation reservation = Reservation.builder() - .status(COMPLETED) - .peopleCount(request.peopleCount()) - .build(); + public ReservationTime validateReservationAndSave(CreateReservationRequest request) { + ReservationTime reservationTime = reservationTimeRepository.findById(request.reservationTimeId()) + .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { - throw new RuntimeException("타인에게 선점권이 있음"); - } - if (reservationTime.isOccupied()) { - throw new RuntimeException("이미 예약된 시간임"); + throw new BadRequestCustomException(IS_PRE_OCCUPIED); } - reservation.insertReservvationTime(reservationTime); - reservation.insertShop(shop); - - Reservation savedReservation = reservationRepository.save(reservation); - - return new ValidateReservationResponse(savedReservation.getShop().getName(), - savedReservation.getTime()); + return reservationTime; } } From 3e1f6c507257fc0af3462feaaa42e2538abd5b42 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:12 +0900 Subject: [PATCH 29/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=8D=BC?= =?UTF-8?q?=EC=82=AC=EB=93=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacade.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index 8cf1f723..a3e26046 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -3,7 +3,6 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; import com.prgrms.catchtable.reservation.service.ReservationService; import lombok.RequiredArgsConstructor; @@ -16,14 +15,12 @@ public class ReservationFacade { private final ReservationService reservationService; private final ReservationAsync reservationAsync; - public CreateReservationResponse createReservation(Long shopId, + public CreateReservationResponse preOccupyReservation ( CreateReservationRequest request) { - ValidateReservationResponse validateReservationResponse = reservationService.validateReservationIsPossible( - shopId, + ReservationTime reservationTime = reservationService.validateReservationAndSave( request); - String shopName = validateReservationResponse.shopName(); - ReservationTime reservationTime = validateReservationResponse.reservationTime(); + String shopName = reservationTime.getShop().getName(); reservationAsync.setPreOcuppied(reservationTime); From 762e4f4f1cf2b5ae81f71fdabdfd26d2dfc1b477 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:40 +0900 Subject: [PATCH 30/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20-=20=EB=A7=A4=EC=9E=A5=20=EC=97=B0=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=ED=8E=B8=EC=9D=98=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 --- .../prgrms/catchtable/reservation/domain/ReservationTime.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index d11f2f8a..319703f0 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -54,4 +54,8 @@ public void reverseOccupied() { public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } + + public void insertShop(Shop shop){ + this.shop = shop; + } } From 84a86fc4c7c40942081c52c197b8219a1724b9c3 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 14:59:55 +0900 Subject: [PATCH 31/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=A6=AC=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reservation/repository/ReservationTimeRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java new file mode 100644 index 00000000..63ae522a --- /dev/null +++ b/src/main/java/com/prgrms/catchtable/reservation/repository/ReservationTimeRepository.java @@ -0,0 +1,8 @@ +package com.prgrms.catchtable.reservation.repository; + +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReservationTimeRepository extends JpaRepository { + +} From 51fb95f9c119cbea263455fc39b2a9f17930399a Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:01:36 +0900 Subject: [PATCH 32/46] =?UTF-8?q?feat=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9A=A9=20=EC=98=88=EC=95=BD=EA=B4=80=EB=A0=A8=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reservation/ReservationData.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 624f3f10..8026898b 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -2,6 +2,7 @@ import static com.prgrms.catchtable.reservation.domain.ReservationStatus.COMPLETED; +import com.prgrms.catchtable.common.data.shop.ShopData; import com.prgrms.catchtable.reservation.domain.Reservation; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; @@ -13,17 +14,29 @@ public static Reservation getReservation() { return Reservation.builder() .status(COMPLETED) .peopleCount(4) + .reservationTime(getReservationTimeNotPreOccupied()) .build(); } - public static ReservationTime getReservationTime() { - return ReservationTime.builder() - .time(LocalDateTime.of(2023, 12, 31, 19, 30)) + public static ReservationTime getReservationTimeNotPreOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 12, 31, 19, 30)) .build(); + reservationTime.insertShop(ShopData.getShop()); + return reservationTime; + } + + public static ReservationTime getReservationTimePreOccupied() { + ReservationTime reservationTime = ReservationTime.builder() + .time(LocalDateTime.of(2024, 12, 31, 19, 30)) + .build(); + reservationTime.insertShop(ShopData.getShop()); + reservationTime.reversePreOccupied(); + return reservationTime; } public static CreateReservationRequest getCreateReservationRequest() { - return new CreateReservationRequest(LocalDateTime.of(2023, 12, 31, 19, 30), 5); + return new CreateReservationRequest(1L, 4); } } From bc306d46bf3b5931ea41607b60fb680fc4b1dd1d Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:02:48 +0900 Subject: [PATCH 33/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=97=AD=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=8F=84=EB=A9=94=EC=9D=B8=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 --- .../catchtable/reservation/domain/ReservationTimeTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java index abade0a4..d8ff901d 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/domain/ReservationTimeTest.java @@ -11,7 +11,7 @@ class ReservationTimeTest { @Test @DisplayName("예약 선점 여부 변경에 성공한다") void reversePreOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTime(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); reservationTime.reversePreOccupied(); assertThat(reservationTime.isPreOccupied()).isTrue(); @@ -20,7 +20,7 @@ void reversePreOccupied() { @Test @DisplayName("예약 여부 변경에 성공한다.") void reverseOccupied() { - ReservationTime reservationTime = ReservationData.getReservationTime(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); reservationTime.reverseOccupied(); assertThat(reservationTime.isOccupied()).isTrue(); From 8b0c940407472b9ca95c4461be120be084d4dc69 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:03:32 +0900 Subject: [PATCH 34/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=EA=B6=8C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=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 --- .../service/ReservationServiceTest.java | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java index a3a64724..80d65ee7 100644 --- a/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java +++ b/src/test/java/com/prgrms/catchtable/reservation/service/ReservationServiceTest.java @@ -2,17 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import static org.mockito.ArgumentMatchers.any; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import com.prgrms.catchtable.common.data.reservation.ReservationData; -import com.prgrms.catchtable.common.data.shop.ShopData; -import com.prgrms.catchtable.reservation.domain.Reservation; +import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; +import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.dto.response.ValidateReservationResponse; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; -import com.prgrms.catchtable.shop.domain.Shop; -import com.prgrms.catchtable.shop.repository.ShopRepository; +import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; import java.util.Optional; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -26,33 +23,47 @@ class ReservationServiceTest { @Mock - private ReservationRepository reservationRepository; - @Mock - private ShopRepository shopRepository; + private ReservationTimeRepository reservationTimeRepository; @InjectMocks private ReservationService reservationService; @Test @DisplayName("예약시간의 선점 여부를 검증하고 선점권이 빈 것을 확인한다.") void validateReservation() { - Reservation reservation = ReservationData.getReservation(); - CreateReservationRequest createReservationRequest = ReservationData.getCreateReservationRequest(); - Shop shop = ShopData.getShop(); - - reservation.insertShop(shop); - reservation.insertReservvationTime(ReservationData.getReservationTime()); + //given + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + ReflectionTestUtils.setField(reservationTime, "id", 1L); - ReflectionTestUtils.setField(shop, "id", 1L); + when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); - when(shopRepository.findById(any(Long.class))).thenReturn(Optional.of(shop)); - when(reservationRepository.save(any(Reservation.class))).thenReturn(reservation); + //when + ReservationTime savedReservationTime = reservationService.validateReservationAndSave( + request); - ValidateReservationResponse response = reservationService.validateReservationIsPossible( - shop.getId(), createReservationRequest); + //then assertAll( - () -> assertThat(response.reservationTime().getTime()).isEqualTo( - createReservationRequest.date()), - () -> assertThat(response.shopName()).isEqualTo(shop.getName()) + () -> assertThat(savedReservationTime.getTime()).isEqualTo(reservationTime.getTime()), + () -> assertThat(savedReservationTime.getShop()).isEqualTo(reservationTime.getShop()) ); + + + } + + @Test + @DisplayName("예약시간 선점권이 이미 타인에게 있는 경우 예외가 발생한다.") + void alreadyPreOccupied() { + //given + ReservationTime reservationTime = ReservationData.getReservationTimePreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + ReflectionTestUtils.setField(reservationTime, "id", 1L); + + when(reservationTimeRepository.findById(1L)).thenReturn(Optional.of(reservationTime)); + + //when + assertThrows(BadRequestCustomException.class, + () -> reservationService.validateReservationAndSave(request)); + + } } \ No newline at end of file From 07b850d12cc3491507e3dab283f5036e6d31a400 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:03:40 +0900 Subject: [PATCH 35/46] =?UTF-8?q?feat=20:=20=EC=98=88=EC=95=BD=20=EC=84=A0?= =?UTF-8?q?=EC=A0=90=20=ED=8D=BC=EC=82=AC=EB=93=9C=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 --- .../facade/ReservationFacadeTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java new file mode 100644 index 00000000..ea27b6cc --- /dev/null +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -0,0 +1,49 @@ +package com.prgrms.catchtable.facade; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import com.prgrms.catchtable.common.data.reservation.ReservationData; +import com.prgrms.catchtable.reservation.domain.ReservationTime; +import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; +import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; +import com.prgrms.catchtable.reservation.service.ReservationAsync; +import com.prgrms.catchtable.reservation.service.ReservationService; +import org.assertj.core.api.Assertions; +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 ReservationFacadeTest { + + @Mock + private ReservationAsync reservationAsync; + @Mock + private ReservationService reservationService; + @InjectMocks + private ReservationFacade reservationFacade; + + @Test + @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") + void preOccupyReservation(){ + ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); + CreateReservationRequest request = ReservationData.getCreateReservationRequest(); + + when(reservationService.validateReservationAndSave(any(CreateReservationRequest.class))).thenReturn(reservationTime); + + CreateReservationResponse response = reservationFacade.preOccupyReservation( + request); + + assertAll( + () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()), + () -> assertThat(reservationTime.isPreOccupied()).isTrue() + ); + } +} \ No newline at end of file From 9dca08806b9a32ee47946bf2cc9445612481bb9f Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:07:01 +0900 Subject: [PATCH 36/46] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/facade/ReservationFacade.java | 2 +- .../catchtable/reservation/domain/ReservationTime.java | 2 +- .../reservation/service/ReservationService.java | 5 ++--- .../catchtable/facade/ReservationFacadeTest.java | 10 +++++----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index a3e26046..bb5ded8a 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -15,7 +15,7 @@ public class ReservationFacade { private final ReservationService reservationService; private final ReservationAsync reservationAsync; - public CreateReservationResponse preOccupyReservation ( + public CreateReservationResponse preOccupyReservation( CreateReservationRequest request) { ReservationTime reservationTime = reservationService.validateReservationAndSave( request); diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java index 319703f0..8b4f6e43 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/ReservationTime.java @@ -55,7 +55,7 @@ public void reversePreOccupied() { this.isPreOccupied = !this.isPreOccupied; } - public void insertShop(Shop shop){ + public void insertShop(Shop shop) { this.shop = shop; } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index d3e25e90..fe22621f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -7,9 +7,7 @@ import com.prgrms.catchtable.common.exception.custom.NotFoundCustomException; import com.prgrms.catchtable.reservation.domain.ReservationTime; import com.prgrms.catchtable.reservation.dto.request.CreateReservationRequest; -import com.prgrms.catchtable.reservation.repository.ReservationRepository; import com.prgrms.catchtable.reservation.repository.ReservationTimeRepository; -import com.prgrms.catchtable.shop.repository.ShopRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +20,8 @@ public class ReservationService { @Transactional public ReservationTime validateReservationAndSave(CreateReservationRequest request) { - ReservationTime reservationTime = reservationTimeRepository.findById(request.reservationTimeId()) + ReservationTime reservationTime = reservationTimeRepository.findById( + request.reservationTimeId()) .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index ea27b6cc..759985f4 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -1,7 +1,7 @@ package com.prgrms.catchtable.facade; -import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -11,7 +11,6 @@ import com.prgrms.catchtable.reservation.dto.response.CreateReservationResponse; import com.prgrms.catchtable.reservation.service.ReservationAsync; import com.prgrms.catchtable.reservation.service.ReservationService; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,11 +30,12 @@ class ReservationFacadeTest { @Test @DisplayName("예약을 검증하고 선점권을 true로 바꾸는 것에 성공한다.") - void preOccupyReservation(){ + void preOccupyReservation() { ReservationTime reservationTime = ReservationData.getReservationTimeNotPreOccupied(); CreateReservationRequest request = ReservationData.getCreateReservationRequest(); - when(reservationService.validateReservationAndSave(any(CreateReservationRequest.class))).thenReturn(reservationTime); + when(reservationService.validateReservationAndSave( + any(CreateReservationRequest.class))).thenReturn(reservationTime); CreateReservationResponse response = reservationFacade.preOccupyReservation( request); From 5c0d43a8dc8c58fcb17f0ea855b62a17d0230d32 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 15:08:21 +0900 Subject: [PATCH 37/46] =?UTF-8?q?fix=20:=20=EC=98=88=EC=95=BD=20=ED=8D=BC?= =?UTF-8?q?=EC=82=AC=EB=93=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacadeTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java index 759985f4..5323b921 100644 --- a/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java +++ b/src/test/java/com/prgrms/catchtable/facade/ReservationFacadeTest.java @@ -42,8 +42,7 @@ void preOccupyReservation() { assertAll( () -> assertThat(response.date()).isEqualTo(reservationTime.getTime()), - () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()), - () -> assertThat(reservationTime.isPreOccupied()).isTrue() + () -> assertThat(response.peopleCount()).isEqualTo(request.peopleCount()) ); } } \ No newline at end of file From ab7d66b1f70c73132dfcb151116caea10f4fbbce Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:28:37 +0900 Subject: [PATCH 38/46] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD=20-=20?= =?UTF-8?q?=EC=98=88=EC=95=BD=EC=8B=9C=EA=B0=84=20=EC=97=B0=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=98=81=EC=86=8D=EC=84=B1=20=EC=A0=84?= =?UTF-8?q?=EC=9D=B4=20=EC=86=8D=EC=84=B1=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/reservation/domain/Reservation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index e9e08d5b..c22ed292 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -47,8 +47,8 @@ public class Reservation extends BaseEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - - @OneToOne(fetch = LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + + @OneToOne(fetch = LAZY) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private ReservationTime reservationTime; From 5e7e42d4113b9d30a573e8f8ac058cace18be11b Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:30:43 +0900 Subject: [PATCH 39/46] =?UTF-8?q?refactor=20:=20dto=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 3 +-- .../reservation/dto/request/CreateReservationRequest.java | 3 ++- .../reservation/dto/response/CreateReservationResponse.java | 4 +++- .../reservation/dto/response/ValidateReservationResponse.java | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index c22ed292..c8bf0a7e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -8,7 +8,6 @@ import com.prgrms.catchtable.common.BaseEntity; import com.prgrms.catchtable.member.domain.Member; import com.prgrms.catchtable.shop.domain.Shop; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.ConstraintMode; import jakarta.persistence.Entity; @@ -47,7 +46,7 @@ public class Reservation extends BaseEntity { @ManyToOne(fetch = LAZY) @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Shop shop; - + @OneToOne(fetch = LAZY) @JoinColumn(name = "reservation_time_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private ReservationTime reservationTime; diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 41c3b6a0..099fa86e 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,5 +1,6 @@ package com.prgrms.catchtable.reservation.dto.request; -public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { +public record CreateReservationRequest(Long reservationTimeId, + int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index 1730ec96..7457a599 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -2,7 +2,9 @@ import java.time.LocalDateTime; -public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, +public record CreateReservationResponse(String shopName, + String memberName, + LocalDateTime date, int peopleCount) { } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java index ee0e91d1..435c8ad8 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -2,6 +2,7 @@ import com.prgrms.catchtable.reservation.domain.ReservationTime; -public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { +public record ValidateReservationResponse(String shopName, + ReservationTime reservationTime) { } From b43c4fa546c28e4b79962af11e03c4b333a910b2 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:46:41 +0900 Subject: [PATCH 40/46] =?UTF-8?q?refactor=20:=20dto=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B9=8C=EB=8D=94=ED=8C=A8=ED=84=B4=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/facade/ReservationFacade.java | 8 ++++++-- .../reservation/dto/request/CreateReservationRequest.java | 3 +++ .../dto/response/CreateReservationResponse.java | 2 ++ .../dto/response/ValidateReservationResponse.java | 2 ++ .../common/data/reservation/ReservationData.java | 5 ++++- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java index bb5ded8a..a00172a5 100644 --- a/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java +++ b/src/main/java/com/prgrms/catchtable/facade/ReservationFacade.java @@ -24,8 +24,12 @@ public CreateReservationResponse preOccupyReservation( reservationAsync.setPreOcuppied(reservationTime); - return new CreateReservationResponse(shopName, "memberA", reservationTime.getTime(), - request.peopleCount()); + return CreateReservationResponse.builder() + .shopName(shopName) + .memberName("memberA") + .date(reservationTime.getTime()) + .peopleCount(request.peopleCount()) + .build(); } } diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java index 099fa86e..94ec2b44 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/request/CreateReservationRequest.java @@ -1,5 +1,8 @@ package com.prgrms.catchtable.reservation.dto.request; +import lombok.Builder; + +@Builder public record CreateReservationRequest(Long reservationTimeId, int peopleCount) { diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java index 7457a599..fb871d6f 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/CreateReservationResponse.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.reservation.dto.response; import java.time.LocalDateTime; +import lombok.Builder; +@Builder public record CreateReservationResponse(String shopName, String memberName, LocalDateTime date, diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java index 435c8ad8..f40f07ef 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java @@ -1,7 +1,9 @@ package com.prgrms.catchtable.reservation.dto.response; import com.prgrms.catchtable.reservation.domain.ReservationTime; +import lombok.Builder; +@Builder public record ValidateReservationResponse(String shopName, ReservationTime reservationTime) { diff --git a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java index 8026898b..f47d9941 100644 --- a/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java +++ b/src/test/java/com/prgrms/catchtable/common/data/reservation/ReservationData.java @@ -36,7 +36,10 @@ public static ReservationTime getReservationTimePreOccupied() { } public static CreateReservationRequest getCreateReservationRequest() { - return new CreateReservationRequest(1L, 4); + return CreateReservationRequest.builder() + .reservationTimeId(1L) + .peopleCount(4) + .build(); } } From d64bdc78140e24dffc362ddd24fd2db1fb3275a9 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Wed, 27 Dec 2023 16:48:26 +0900 Subject: [PATCH 41/46] =?UTF-8?q?remove=20:=20ValidateReservationResponse?= =?UTF-8?q?=20dto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/ValidateReservationResponse.java | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java diff --git a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java b/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java deleted file mode 100644 index f40f07ef..00000000 --- a/src/main/java/com/prgrms/catchtable/reservation/dto/response/ValidateReservationResponse.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.prgrms.catchtable.reservation.dto.response; - -import com.prgrms.catchtable.reservation.domain.ReservationTime; -import lombok.Builder; - -@Builder -public record ValidateReservationResponse(String shopName, - ReservationTime reservationTime) { - -} From 51c0f2eed56fe2f828e7b44b262dc39e0771d87e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:51:09 +0900 Subject: [PATCH 42/46] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EB=AF=B8=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/service/ReservationAsync.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java index 2d495747..c9a1e897 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationAsync.java @@ -5,13 +5,11 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @Component @RequiredArgsConstructor -@Slf4j public class ReservationAsync { @Transactional From 44e3c40bc2c6cbe0bdea1a9c5c2d39c065576fae Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:52:48 +0900 Subject: [PATCH 43/46] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD-?= =?UTF-8?q?=EB=A7=A4=EC=9E=A5=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84=20?= =?UTF-8?q?=EB=A7=A4=ED=95=91=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B4=88=EA=B8=B0=ED=99=94=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms/catchtable/reservation/domain/Reservation.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index c8bf0a7e..f7e9f076 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -52,13 +52,11 @@ public class Reservation extends BaseEntity { private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount, ReservationTime reservationTime) { + public Reservation(ReservationStatus status, int peopleCount, Shop shop, ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; + this.shop = shop; this.reservationTime = reservationTime; } - public void insertShop(Shop shop) { - this.shop = shop; - } } From 8eaf6ec958f8f7d9af84d204a0da7a1b36d2b97e Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:53:26 +0900 Subject: [PATCH 44/46] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/reservation/domain/Reservation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java index f7e9f076..db66a48b 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java +++ b/src/main/java/com/prgrms/catchtable/reservation/domain/Reservation.java @@ -52,7 +52,8 @@ public class Reservation extends BaseEntity { private ReservationTime reservationTime; @Builder - public Reservation(ReservationStatus status, int peopleCount, Shop shop, ReservationTime reservationTime) { + public Reservation(ReservationStatus status, int peopleCount, Shop shop, + ReservationTime reservationTime) { this.status = status; this.peopleCount = peopleCount; this.shop = shop; From 2898a36d19a0976534b8fb58bc6c3a44d004bf07 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 13:59:17 +0900 Subject: [PATCH 45/46] =?UTF-8?q?refactor=20:=20=EC=98=88=EC=95=BD?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=84=A0=EC=A0=90=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/prgrms/catchtable/common/exception/ErrorCode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 45db60e4..02c9e311 100644 --- a/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java +++ b/src/main/java/com/prgrms/catchtable/common/exception/ErrorCode.java @@ -7,8 +7,8 @@ @RequiredArgsConstructor public enum ErrorCode { NOT_EXIST_MEMBER("존재하지 않는 아이디입니다."), - IS_PRE_OCCUPIED("이미 타인에게 선점권이 있는 예약시간입니다."), - IS_OCCUPIED("이미 예약된 시간입니다."), + ALREADY_PREOCCUPIED_RESERVATION_TIME("이미 타인에게 선점권이 있는 예약시간입니다."), + ALREADY_OCCUPIED_RESERVATION_TIME("이미 예약된 시간입니다."), NOT_EXIST_SHOP("존재하지 않는 매장입니다."), NOT_EXIST_TIME("존재하지 않는 예약 시간입니다."); From bd8a90fbeb28fce7962cb4b5ec3c35be7853ea67 Mon Sep 17 00:00:00 2001 From: dlswns2480 Date: Thu, 28 Dec 2023 14:05:13 +0900 Subject: [PATCH 46/46] =?UTF-8?q?fix=20:=20Errorcode=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=98=88=EC=99=B8=20=EB=8D=98?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catchtable/reservation/service/ReservationService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java index fe22621f..343a1293 100644 --- a/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java +++ b/src/main/java/com/prgrms/catchtable/reservation/service/ReservationService.java @@ -1,6 +1,6 @@ package com.prgrms.catchtable.reservation.service; -import static com.prgrms.catchtable.common.exception.ErrorCode.IS_PRE_OCCUPIED; +import static com.prgrms.catchtable.common.exception.ErrorCode.ALREADY_PREOCCUPIED_RESERVATION_TIME; import static com.prgrms.catchtable.common.exception.ErrorCode.NOT_EXIST_TIME; import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException; @@ -25,7 +25,7 @@ public ReservationTime validateReservationAndSave(CreateReservationRequest reque .orElseThrow(() -> new NotFoundCustomException(NOT_EXIST_TIME)); if (reservationTime.isPreOccupied()) { - throw new BadRequestCustomException(IS_PRE_OCCUPIED); + throw new BadRequestCustomException(ALREADY_PREOCCUPIED_RESERVATION_TIME); } return reservationTime;