From 9d97b06b9b1418bd05b764e5ef933ff0f5a2ef32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=A7=80=EC=9B=90?= Date: Wed, 21 Aug 2024 17:34:52 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20mealDelivery=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20orderType=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 배송목록 조회시에 배송목록 한개당 orderType의 조회를 위해 APi 요청을 1개씩 또 보내야하는 이슈 -> 비정규화 진행 --- .../api/mealdelivery/MealDeliveryApi.java | 3 ++ .../dto/MealDeliveryResponse.java | 3 ++ .../domain/mealdelivery/DeliveryDateTime.java | 49 ++++++++++++++---- .../domain/mealdelivery/DeliveryState.java | 1 + .../domain/mealdelivery/MealDelivery.java | 37 ++++++++++---- .../mealdelivery/MealDeliveryService.java | 6 +++ .../mealdelivery/MealDeliveryUpdater.java | 7 ++- .../mealdelivery/OrderTypeForDelivery.java | 6 +++ .../MealDeliveryDomainException.java | 10 ++++ .../exception/MealDeliveryErrorCode.java | 20 ++++++-- .../mealtoktok/domain/order/OrderContent.java | 7 ++- .../mealtoktok/domain/order/OrderType.java | 11 +++- .../dishstore/entity/DishStoreEntity.java | 2 +- .../{user => global}/entity/AddressVO.java | 2 +- .../infra/global/entity/ImageEntity.java | 41 +++++++++++++++ .../entity/MealDeliveryEntity.java | 37 +++++++++++--- .../repository/FullDiningJpaRepository.java | 26 +++++----- .../repository/MealDeliveryJpaRepository.java | 26 +++++----- .../MealDeliveryJpaRepositoryImpl.java | 4 +- .../repository/OrderJpaRepositoryImpl.java | 4 +- .../user/entity/DeliveryAddressEntity.java | 1 + .../infra/user/entity/UserEntity.java | 36 +++++++++++++ .../infra/user/entity/UserProfileVO.java | 50 ------------------- 23 files changed, 271 insertions(+), 118 deletions(-) create mode 100644 domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/OrderTypeForDelivery.java create mode 100644 domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryDomainException.java rename infra/src/main/java/core/startup/mealtoktok/infra/{user => global}/entity/AddressVO.java (92%) create mode 100644 infra/src/main/java/core/startup/mealtoktok/infra/global/entity/ImageEntity.java delete mode 100644 infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserProfileVO.java diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/MealDeliveryApi.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/MealDeliveryApi.java index 9c56a67..6620518 100644 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/MealDeliveryApi.java +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/MealDeliveryApi.java @@ -81,6 +81,9 @@ public Response changeDeliveryState( @PathVariable Long mealDeliveryId, @PathVariable DeliveryState deliveryState) { switch (deliveryState) { + case DELIVERY_REQUESTED -> + mealDeliveryService.reserveMealDelivery( + TargetMealDelivery.from(mealDeliveryId)); case DELIVERING -> mealDeliveryService.startMealDelivery(TargetMealDelivery.from(mealDeliveryId)); case DELIVERED -> diff --git a/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/dto/MealDeliveryResponse.java b/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/dto/MealDeliveryResponse.java index 498aa09..76f7ecf 100644 --- a/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/dto/MealDeliveryResponse.java +++ b/application/app-api/src/main/java/core/startup/mealtoktok/api/mealdelivery/dto/MealDeliveryResponse.java @@ -5,6 +5,7 @@ import core.startup.mealtoktok.domain.mealdelivery.DeliveryDateTime; import core.startup.mealtoktok.domain.mealdelivery.DeliveryState; import core.startup.mealtoktok.domain.mealdelivery.MealDelivery; +import core.startup.mealtoktok.domain.mealdelivery.OrderTypeForDelivery; import core.startup.mealtoktok.domain.mealdelivery.OrderedMeal; import com.fasterxml.jackson.annotation.JsonInclude; @@ -13,6 +14,7 @@ public record MealDeliveryResponse( Long mealDeliveryId, Long orderId, + OrderTypeForDelivery orderType, OrderedMeal orderedMeal, DeliveryState deliveryState, DeliveryDateTime deliveryDateTime) { @@ -21,6 +23,7 @@ public static MealDeliveryResponse from(MealDelivery mealDelivery) { return new MealDeliveryResponse( mealDelivery.getMealDeliveryId(), mealDelivery.getOrderId(), + mealDelivery.getOrderType(), mealDelivery.getOrderedMeal(), mealDelivery.getDeliveryState(), mealDelivery.getDeliveryDateTime()); diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryDateTime.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryDateTime.java index 985788b..6921fc3 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryDateTime.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryDateTime.java @@ -2,24 +2,53 @@ import java.time.LocalDateTime; -public record DeliveryDateTime( - LocalDateTime deliveryStartTime, LocalDateTime deliveryCompleteTime) { +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class DeliveryDateTime { + + private final LocalDateTime deliveryRequestTime; + private final LocalDateTime deliveryStartTime; + private final LocalDateTime deliveryCompleteTime; + + public LocalDateTime getDeliveryRequestTime() { + return deliveryRequestTime; + } + + public LocalDateTime getDeliveryStartTime() { + return deliveryStartTime; + } + + public LocalDateTime getDeliveryCompleteTime() { + return deliveryCompleteTime; + } public static DeliveryDateTime of( - LocalDateTime deliveryStartTime, LocalDateTime deliveryCompleteTime) { - return new DeliveryDateTime(deliveryStartTime, deliveryCompleteTime); + LocalDateTime deliveryReservedTime, + LocalDateTime deliveryStartTime, + LocalDateTime deliveryCompleteTime) { + return new DeliveryDateTime(deliveryReservedTime, deliveryStartTime, deliveryCompleteTime); + } + + public static DeliveryDateTime deliveryRequest(DeliveryDateTime deliveryDateTime) { + return new DeliveryDateTime(LocalDateTime.now(), null, null); } - public static DeliveryDateTime start(LocalDateTime deliveryStartTime) { - return new DeliveryDateTime(deliveryStartTime, null); + public static DeliveryDateTime start(DeliveryDateTime deliveryDateTime) { + return new DeliveryDateTime( + deliveryDateTime.getDeliveryRequestTime(), LocalDateTime.now(), null); } - public static DeliveryDateTime complete( - LocalDateTime deliveryStartTime, LocalDateTime deliveryCompleteTime) { - return new DeliveryDateTime(deliveryStartTime, deliveryCompleteTime); + public static DeliveryDateTime complete(DeliveryDateTime deliveryDateTime) { + return new DeliveryDateTime( + deliveryDateTime.getDeliveryRequestTime(), + deliveryDateTime.getDeliveryStartTime(), + LocalDateTime.now()); } public static DeliveryDateTime init() { - return new DeliveryDateTime(null, null); + return new DeliveryDateTime(null, null, null); } } diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryState.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryState.java index 2ed3786..2fd0064 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryState.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/DeliveryState.java @@ -2,6 +2,7 @@ public enum DeliveryState { PENDING, + DELIVERY_REQUESTED, DELIVERING, DELIVERED } diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDelivery.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDelivery.java index 6599514..9f20b0f 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDelivery.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDelivery.java @@ -1,12 +1,12 @@ package core.startup.mealtoktok.domain.mealdelivery; -import java.time.LocalDateTime; - import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import core.startup.mealtoktok.domain.mealdelivery.exception.MealDeliveryDomainException; + @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @Builder @@ -14,24 +14,43 @@ public class MealDelivery { private Long mealDeliveryId; private Long orderId; + private OrderTypeForDelivery orderType; private OrderedMeal orderedMeal; private DeliveryState deliveryState; private DeliveryDateTime deliveryDateTime; - public void startDelivery(LocalDateTime startDateTime) { - this.deliveryDateTime = DeliveryDateTime.start(startDateTime); + public void deliveryRequest() { + this.deliveryDateTime = DeliveryDateTime.deliveryRequest(deliveryDateTime); + this.deliveryState = DeliveryState.DELIVERY_REQUESTED; + } + + public void startDelivery() { + if (deliveryState != DeliveryState.DELIVERY_REQUESTED) { + throw new MealDeliveryDomainException("배송예약없이 배송을 시작할 수 없습니다."); + } + + this.deliveryDateTime = DeliveryDateTime.start(deliveryDateTime); this.deliveryState = DeliveryState.DELIVERING; } - public void completeDelivery(LocalDateTime completeDateTime) { - this.deliveryDateTime = - DeliveryDateTime.complete(deliveryDateTime.deliveryStartTime(), completeDateTime); + public void completeDelivery() { + if (deliveryState != DeliveryState.DELIVERING) { + throw new MealDeliveryDomainException("배송중이 아닌 주문은 배송완료처리할 수 없습니다."); + } + + this.deliveryDateTime = DeliveryDateTime.complete(deliveryDateTime); this.deliveryState = DeliveryState.DELIVERED; } - public static MealDelivery create(Long orderId, OrderedMeal orderedMeal) { + public static MealDelivery create( + Long orderId, OrderTypeForDelivery orderTypeForDelivery, OrderedMeal orderedMeal) { return new MealDelivery( - null, orderId, orderedMeal, DeliveryState.PENDING, DeliveryDateTime.init()); + null, + orderId, + orderTypeForDelivery, + orderedMeal, + DeliveryState.PENDING, + DeliveryDateTime.init()); } public boolean hasFullDiningOption() { diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryService.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryService.java index db02d8c..59cc7b4 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryService.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryService.java @@ -35,6 +35,12 @@ public MealDelivery getMealDelivery(TargetMealDelivery targetMealDelivery) { return mealDeliveryReader.read(targetMealDelivery); } + public void reserveMealDelivery(TargetMealDelivery targetMealDelivery) { + MealDelivery mealDelivery = mealDeliveryReader.read(targetMealDelivery); + mealDeliveryUpdater.changeDeliveryState(mealDelivery, DeliveryState.DELIVERY_REQUESTED); + // TODO :알림 발송 alarmSender.send(orderer, DeliveryState.DELIVERY_RESERVED); + } + public void startMealDelivery(TargetMealDelivery targetMealDelivery) { MealDelivery mealDelivery = mealDeliveryReader.read(targetMealDelivery); mealDeliveryUpdater.changeDeliveryState(mealDelivery, DeliveryState.DELIVERING); diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryUpdater.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryUpdater.java index dc691e6..bac7aac 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryUpdater.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/MealDeliveryUpdater.java @@ -1,7 +1,5 @@ package core.startup.mealtoktok.domain.mealdelivery; -import java.time.LocalDateTime; - import org.springframework.stereotype.Component; import lombok.RequiredArgsConstructor; @@ -14,8 +12,9 @@ public class MealDeliveryUpdater { public void changeDeliveryState(MealDelivery mealDelivery, DeliveryState deliveryState) { switch (deliveryState) { - case DELIVERING -> mealDelivery.startDelivery(LocalDateTime.now()); - case DELIVERED -> mealDelivery.completeDelivery(LocalDateTime.now()); + case DELIVERY_REQUESTED -> mealDelivery.deliveryRequest(); + case DELIVERING -> mealDelivery.startDelivery(); + case DELIVERED -> mealDelivery.completeDelivery(); } mealDeliveryRepository.update(mealDelivery); } diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/OrderTypeForDelivery.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/OrderTypeForDelivery.java new file mode 100644 index 0000000..98cc9ba --- /dev/null +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/OrderTypeForDelivery.java @@ -0,0 +1,6 @@ +package core.startup.mealtoktok.domain.mealdelivery; + +public enum OrderTypeForDelivery { + IMMEDIATE, + SCHEDULED +} diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryDomainException.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryDomainException.java new file mode 100644 index 0000000..0ec336a --- /dev/null +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryDomainException.java @@ -0,0 +1,10 @@ +package core.startup.mealtoktok.domain.mealdelivery.exception; + +import core.startup.mealtoktok.common.exception.DomainException; + +public class MealDeliveryDomainException extends DomainException { + + public MealDeliveryDomainException(String message) { + super(MealDeliveryErrorCode.MEAL_DELIVERY_DOMAIN_ERROR.setMessage(message)); + } +} diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryErrorCode.java b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryErrorCode.java index a8cb1ce..751e721 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryErrorCode.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/mealdelivery/exception/MealDeliveryErrorCode.java @@ -2,20 +2,32 @@ import static core.startup.mealtoktok.common.consts.MealTokTokConstant.NOT_FOUND; -import lombok.RequiredArgsConstructor; +import lombok.AllArgsConstructor; import core.startup.mealtoktok.common.exception.BaseErrorCode; import core.startup.mealtoktok.common.exception.ErrorReason; -@RequiredArgsConstructor +@AllArgsConstructor public enum MealDeliveryErrorCode implements BaseErrorCode { MEAL_DELIVERY_NOT_FOUND(NOT_FOUND, "MEAL_DELIVERY_404_1", "배송 정보를 찾지 못했습니다"), NEXT_MEAL_DELIVERY_NOT_FOUND(NOT_FOUND, "MEAL_DELIVERY_404_2", "다음 배송 정보를 찾지 못했습니다"), - FULL_DINING_NOT_FOUND(NOT_FOUND, "FULL_DINING_404_1", "풀대접 정보를 찾지 못했습니다"); + FULL_DINING_NOT_FOUND(NOT_FOUND, "FULL_DINING_404_1", "풀대접 정보를 찾지 못했습니다"), + MEAL_DELIVERY_DOMAIN_ERROR(500, "MEAL_DELIVERY_500_1"); + + MealDeliveryErrorCode(Integer status, String errorCode) { + this.status = status; + this.errorCode = errorCode; + } private final Integer status; private final String errorCode; - private final String message; + + private String message; + + public BaseErrorCode setMessage(String message) { + this.message = message; + return this; + } @Override public ErrorReason getErrorReason() { diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderContent.java b/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderContent.java index 7b6fb8a..812f00f 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderContent.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderContent.java @@ -13,7 +13,12 @@ public record OrderContent( public List toMealDeliveries(TargetOrder targetOrder) { return orderedMeals.stream() - .map(orderedMeal -> MealDelivery.create(targetOrder.orderId(), orderedMeal)) + .map( + orderedMeal -> + MealDelivery.create( + targetOrder.orderId(), + orderType.toOrderTypeForDelivery(), + orderedMeal)) .toList(); } } diff --git a/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderType.java b/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderType.java index 624bf1f..d118184 100644 --- a/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderType.java +++ b/domain/src/main/java/core/startup/mealtoktok/domain/order/OrderType.java @@ -1,6 +1,15 @@ package core.startup.mealtoktok.domain.order; +import core.startup.mealtoktok.domain.mealdelivery.OrderTypeForDelivery; + public enum OrderType { IMMEDIATE, - SCHEDULED + SCHEDULED; + + public OrderTypeForDelivery toOrderTypeForDelivery() { + return switch (this) { + case IMMEDIATE -> OrderTypeForDelivery.IMMEDIATE; + case SCHEDULED -> OrderTypeForDelivery.SCHEDULED; + }; + } } diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/dishstore/entity/DishStoreEntity.java b/infra/src/main/java/core/startup/mealtoktok/infra/dishstore/entity/DishStoreEntity.java index bc36091..396a3f0 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/dishstore/entity/DishStoreEntity.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/dishstore/entity/DishStoreEntity.java @@ -21,7 +21,7 @@ import core.startup.mealtoktok.domain.dishstore.OperatingHour; import core.startup.mealtoktok.domain.user.AddressWithCoordinate; import core.startup.mealtoktok.domain.user.Coordinate; -import core.startup.mealtoktok.infra.user.entity.AddressVO; +import core.startup.mealtoktok.infra.global.entity.AddressVO; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/AddressVO.java b/infra/src/main/java/core/startup/mealtoktok/infra/global/entity/AddressVO.java similarity index 92% rename from infra/src/main/java/core/startup/mealtoktok/infra/user/entity/AddressVO.java rename to infra/src/main/java/core/startup/mealtoktok/infra/global/entity/AddressVO.java index 6e47f3c..b588b04 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/AddressVO.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/global/entity/AddressVO.java @@ -1,4 +1,4 @@ -package core.startup.mealtoktok.infra.user.entity; +package core.startup.mealtoktok.infra.global.entity; import jakarta.persistence.Embeddable; diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/global/entity/ImageEntity.java b/infra/src/main/java/core/startup/mealtoktok/infra/global/entity/ImageEntity.java new file mode 100644 index 0000000..38d10ff --- /dev/null +++ b/infra/src/main/java/core/startup/mealtoktok/infra/global/entity/ImageEntity.java @@ -0,0 +1,41 @@ +package core.startup.mealtoktok.infra.global.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import core.startup.mealtoktok.common.dto.Image; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Getter +@Table(name = "image") +public class ImageEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String imageUrl; + + public static ImageEntity from(Image image) { + + if (image == null) { + return null; + } + + return new ImageEntity(image.getId() != null ? image.getId() : null, image.getImageUrl()); + } + + public Image toImage() { + return new Image(id, imageUrl); + } +} diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/entity/MealDeliveryEntity.java b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/entity/MealDeliveryEntity.java index aba7cb4..9f7d544 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/entity/MealDeliveryEntity.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/entity/MealDeliveryEntity.java @@ -3,6 +3,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import jakarta.persistence.Embeddable; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -48,8 +50,7 @@ public class MealDeliveryEntity extends BaseTimeEntity { @Enumerated(EnumType.STRING) private DeliveryState deliveryState; - private LocalDateTime deliveryStartTime; - private LocalDateTime deliveryCompleteTime; + @Embedded private DeliveryDateTimeVO deliveryDateTime; public static MealDeliveryEntity from(MealDelivery mealDelivery) { return MealDeliveryEntity.builder() @@ -60,8 +61,7 @@ public static MealDeliveryEntity from(MealDelivery mealDelivery) { .reservedTime(mealDelivery.getOrderedMeal().reservedSchedule().reservedTime()) .hasFullDiningOption(mealDelivery.getOrderedMeal().hasFullDiningOption()) .deliveryState(mealDelivery.getDeliveryState()) - .deliveryStartTime(mealDelivery.getDeliveryDateTime().deliveryStartTime()) - .deliveryCompleteTime(mealDelivery.getDeliveryDateTime().deliveryCompleteTime()) + .deliveryDateTime(DeliveryDateTimeVO.from(mealDelivery.getDeliveryDateTime())) .build(); } @@ -77,13 +77,36 @@ public MealDelivery toDomain() { includeRice, hasFullDiningOption)) .deliveryState(deliveryState) - .deliveryDateTime(DeliveryDateTime.of(deliveryStartTime, deliveryCompleteTime)) + .deliveryDateTime(deliveryDateTime.toDomain()) .build(); } public void update(MealDelivery mealDelivery) { this.deliveryState = mealDelivery.getDeliveryState(); - this.deliveryStartTime = mealDelivery.getDeliveryDateTime().deliveryStartTime(); - this.deliveryCompleteTime = mealDelivery.getDeliveryDateTime().deliveryCompleteTime(); + this.deliveryDateTime = DeliveryDateTimeVO.from(mealDelivery.getDeliveryDateTime()); + } + + @Embeddable + @AllArgsConstructor + @NoArgsConstructor(access = AccessLevel.PROTECTED) + @Builder + public static class DeliveryDateTimeVO { + + private LocalDateTime deliveryRequestTime; + private LocalDateTime deliveryStartTime; + private LocalDateTime deliveryCompleteTime; + + public static DeliveryDateTimeVO from(DeliveryDateTime deliveryDateTime) { + return DeliveryDateTimeVO.builder() + .deliveryRequestTime(deliveryDateTime.getDeliveryRequestTime()) + .deliveryStartTime(deliveryDateTime.getDeliveryStartTime()) + .deliveryCompleteTime(deliveryDateTime.getDeliveryCompleteTime()) + .build(); + } + + public DeliveryDateTime toDomain() { + return DeliveryDateTime.of( + deliveryRequestTime, deliveryStartTime, deliveryCompleteTime); + } } } diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/FullDiningJpaRepository.java b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/FullDiningJpaRepository.java index e420959..639582e 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/FullDiningJpaRepository.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/FullDiningJpaRepository.java @@ -15,23 +15,23 @@ public interface FullDiningJpaRepository extends JpaRepository= :validDateTime - """) + select fd from FullDiningEntity fd + join MealDeliveryEntity md on fd.mealDeliveryId = md.mealDeliveryId + join OrderEntity od on md.orderId = od.orderId + where od.orderer.userId = :#{#recipient.userId()} + and md.deliveryState = :deliveryState + and md.deliveryDateTime.deliveryCompleteTime >= :validDateTime + """) List findByOrdererAndDeliveryStateAndValidPeriod( Recipient recipient, DeliveryState deliveryState, LocalDateTime validDateTime); @Query( """ - select count(fd) from FullDiningEntity fd - join MealDeliveryEntity md on fd.mealDeliveryId = md.mealDeliveryId - join OrderEntity od on md.orderId = od.orderId - where od.orderer = :#{#recipient.userId()} - and fd.collectingState = :collectingState - """) + select count(fd) from FullDiningEntity fd + join MealDeliveryEntity md on fd.mealDeliveryId = md.mealDeliveryId + join OrderEntity od on md.orderId = od.orderId + where od.orderer = :#{#recipient.userId()} + and fd.collectingState = :collectingState + """) long countByOrdererAndCollectingState(Recipient recipient, CollectingState collectingState); } diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepository.java b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepository.java index a233484..f07f2e6 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepository.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepository.java @@ -18,24 +18,24 @@ public interface MealDeliveryJpaRepository @Query( """ - SELECT mealDelivery - FROM MealDeliveryEntity mealDelivery - JOIN OrderEntity oe on oe.orderId = mealDelivery.orderId - WHERE oe.orderer.userId = :#{#recipient.userId()} - AND mealDelivery.deliveryState = :deliveryState - """) + SELECT mealDelivery + FROM MealDeliveryEntity mealDelivery + JOIN OrderEntity oe on oe.orderId = mealDelivery.orderId + WHERE oe.orderer.userId = :#{#recipient.userId()} + AND mealDelivery.deliveryState = :deliveryState + """) Optional findByOrdererAndDeliveryState( Recipient recipient, DeliveryState deliveryState); @Query( """ - SELECT mealDelivery - FROM MealDeliveryEntity mealDelivery - JOIN OrderEntity oe on oe.orderId = mealDelivery.orderId - WHERE oe.orderer.userId = :#{#recipient.userId()} - AND mealDelivery.deliveryState = :deliveryState - AND mealDelivery.deliveryCompleteTime between :startTime and :endTime - """) + SELECT mealDelivery + FROM MealDeliveryEntity mealDelivery + JOIN OrderEntity oe on oe.orderId = mealDelivery.orderId + WHERE oe.orderer.userId = :#{#recipient.userId()} + AND mealDelivery.deliveryState = :deliveryState + AND mealDelivery.deliveryDateTime.deliveryCompleteTime between :startTime and :endTime + """) Optional findByOrdererAndDeliveryStateAndTime( Recipient recipient, DeliveryState deliveryState, diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepositoryImpl.java b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepositoryImpl.java index 72a066d..2cfaca8 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepositoryImpl.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/mealdelivery/repository/MealDeliveryJpaRepositoryImpl.java @@ -1,7 +1,7 @@ package core.startup.mealtoktok.infra.mealdelivery.repository; -import static core.startup.mealtoktok.infra.mealdelivery.entity.QMealDeliveryEntity.*; -import static core.startup.mealtoktok.infra.order.entity.QOrderEntity.*; +import static core.startup.mealtoktok.infra.mealdelivery.entity.QMealDeliveryEntity.mealDeliveryEntity; +import static core.startup.mealtoktok.infra.order.entity.QOrderEntity.orderEntity; import java.util.List; diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/order/repository/OrderJpaRepositoryImpl.java b/infra/src/main/java/core/startup/mealtoktok/infra/order/repository/OrderJpaRepositoryImpl.java index c460bc1..c3cbc08 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/order/repository/OrderJpaRepositoryImpl.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/order/repository/OrderJpaRepositoryImpl.java @@ -1,7 +1,7 @@ package core.startup.mealtoktok.infra.order.repository; -import static core.startup.mealtoktok.infra.order.entity.QOrderEntity.*; -import static core.startup.mealtoktok.infra.user.entity.QUserEntity.*; +import static core.startup.mealtoktok.infra.order.entity.QOrderEntity.orderEntity; +import static core.startup.mealtoktok.infra.user.entity.QUserEntity.userEntity; import java.util.List; diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/DeliveryAddressEntity.java b/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/DeliveryAddressEntity.java index fc0e4b8..9690f0c 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/DeliveryAddressEntity.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/DeliveryAddressEntity.java @@ -29,6 +29,7 @@ import core.startup.mealtoktok.domain.user.Coordinate; import core.startup.mealtoktok.domain.user.DeliveryAddress; import core.startup.mealtoktok.domain.user.TargetUser; +import core.startup.mealtoktok.infra.global.entity.AddressVO; @Entity @Builder diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserEntity.java b/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserEntity.java index f759231..eafbd1a 100644 --- a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserEntity.java +++ b/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserEntity.java @@ -1,5 +1,6 @@ package core.startup.mealtoktok.infra.user.entity; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; @@ -160,4 +161,39 @@ private void removeNonExistingDeliveryAddresses(User user) { !userDeliveryAddressIds.contains( deliveryAddressEntity.getDeliveryAddressId())); } + + @Embeddable + @NoArgsConstructor(access = AccessLevel.PROTECTED) + @AllArgsConstructor + @Builder + public static class UserProfileVO { + + private String username; + private String nickname; + private String phoneNumber; + private String email; + private String profileImageUrl; + + @Enumerated(EnumType.STRING) + private Gender gender; + + private LocalDate birth; + + public static UserProfileVO from(UserProfile userProfile) { + return UserProfileVO.builder() + .username(userProfile.getUsername()) + .nickname(userProfile.getNickname()) + .phoneNumber(userProfile.getPhoneNumber()) + .email(userProfile.getEmail()) + .profileImageUrl(userProfile.getProfileImageUrl()) + .gender(userProfile.getGender()) + .birth(userProfile.getBirth()) + .build(); + } + + public UserProfile toDomain() { + return UserProfile.of( + username, nickname, gender, phoneNumber, birth, email, profileImageUrl); + } + } } diff --git a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserProfileVO.java b/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserProfileVO.java deleted file mode 100644 index 78f7530..0000000 --- a/infra/src/main/java/core/startup/mealtoktok/infra/user/entity/UserProfileVO.java +++ /dev/null @@ -1,50 +0,0 @@ -package core.startup.mealtoktok.infra.user.entity; - -import java.time.LocalDate; - -import jakarta.persistence.Embeddable; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.NoArgsConstructor; - -import core.startup.mealtoktok.domain.user.Gender; -import core.startup.mealtoktok.domain.user.UserProfile; - -@Embeddable -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Builder -public class UserProfileVO { - - private String username; - private String nickname; - private String phoneNumber; - private String email; - private String profileImageUrl; - - @Enumerated(EnumType.STRING) - private Gender gender; - - private LocalDate birth; - - public static UserProfileVO from(UserProfile userProfile) { - return UserProfileVO.builder() - .username(userProfile.getUsername()) - .nickname(userProfile.getNickname()) - .phoneNumber(userProfile.getPhoneNumber()) - .email(userProfile.getEmail()) - .profileImageUrl(userProfile.getProfileImageUrl()) - .gender(userProfile.getGender()) - .birth(userProfile.getBirth()) - .build(); - } - - public UserProfile toDomain() { - return UserProfile.of( - username, nickname, gender, phoneNumber, birth, email, profileImageUrl); - } -}