diff --git a/db/src/main/java/db/domain/goods/GoodsRepository.java b/db/src/main/java/db/domain/goods/GoodsRepository.java index 0ba4bd3b..66f23efc 100644 --- a/db/src/main/java/db/domain/goods/GoodsRepository.java +++ b/db/src/main/java/db/domain/goods/GoodsRepository.java @@ -13,7 +13,7 @@ public interface GoodsRepository extends JpaRepository { List findAllByIdIn(List goodsIdList); - List findAllByStatusOrderByIdDesc(GoodsStatus status); + List findAllByStatusAndUserIdOrderByIdDesc(GoodsStatus status, Long userId); List findAllByTakeBackIdOrderByIdDesc(Long takeBackId); diff --git a/db/src/main/java/db/domain/receiving/ReceivingRepository.java b/db/src/main/java/db/domain/receiving/ReceivingRepository.java index 91220ea2..9452f318 100644 --- a/db/src/main/java/db/domain/receiving/ReceivingRepository.java +++ b/db/src/main/java/db/domain/receiving/ReceivingRepository.java @@ -1,8 +1,10 @@ package db.domain.receiving; import db.domain.receiving.enums.ReceivingStatus; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import jdk.jshell.Snippet.Kind; import org.springframework.data.jpa.repository.JpaRepository; public interface ReceivingRepository extends JpaRepository { @@ -12,4 +14,6 @@ public interface ReceivingRepository extends JpaRepository findAllByUserIdOrderByIdDesc(Long userId); List findAllByStatusOrderByVisitDate(ReceivingStatus receivingStatus); + + List findAllByStatusAndVisitDateBetweenOrderByUserId (ReceivingStatus receivingStatus, LocalDateTime startDate, LocalDateTime dueDate); } diff --git a/db/src/main/java/db/domain/shipping/ShippingRepository.java b/db/src/main/java/db/domain/shipping/ShippingRepository.java index fd946bcf..b4fa426b 100644 --- a/db/src/main/java/db/domain/shipping/ShippingRepository.java +++ b/db/src/main/java/db/domain/shipping/ShippingRepository.java @@ -1,7 +1,7 @@ package db.domain.shipping; -import db.domain.receiving.ReceivingEntity; import db.domain.shipping.enums.ShippingStatus; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,4 +14,6 @@ public interface ShippingRepository extends JpaRepository List findAllByStatusOrderByDeliveryDate(ShippingStatus shippingStatus); + List findAllByStatusAndDeliveryDateBetweenOrderByUserId(ShippingStatus status, + LocalDateTime startDate, LocalDateTime dueDate); } diff --git a/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java b/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java index 8068ad9a..43f6439b 100644 --- a/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java +++ b/delivery/src/main/java/delivery/common/error/GoodsErrorCode.java @@ -12,7 +12,10 @@ public enum GoodsErrorCode implements ErrorCodeIfs { GOODS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1200, "물품이 존재하지 않습니다."), INVALID_GOODS_STATUS(HttpStatus.BAD_REQUEST.value(),1201,"잘못된 물품 상태입니다."), INVALID_GOODS_STRATEGY(HttpStatus.BAD_REQUEST.value(), 1202, "요청서 종류가 잘못되었습니다."), - NOT_OWNER(HttpStatus.NOT_ACCEPTABLE.value(), 1203, "소유자가 아닙니다.") + NOT_OWNER(HttpStatus.NOT_ACCEPTABLE.value(), 1203, "소유자가 아닙니다."), + GOODS_NOT_IN_STORAGE(HttpStatus.NOT_FOUND.value(),1253,"입고 확정 상태가 아닙니다."), + GOODS_NOT_IN_SHIPPING_ING(HttpStatus.NOT_FOUND.value(),1253,"상품이 출고 진행 상태가 아닙니다."), + GOODS_NOT_IN_RECEIVING(HttpStatus.NOT_FOUND.value(),1253,"상품이 입고 진행 상태가 아닙니다."), ; private final Integer httpCode; diff --git a/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java b/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java index 01bb3b07..a6166a68 100644 --- a/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java +++ b/delivery/src/main/java/delivery/common/error/ReceivingErrorCode.java @@ -11,7 +11,9 @@ public enum ReceivingErrorCode implements ErrorCodeIfs { RECEIVING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1250, "입고 요청서가 존재하지 않습니다."), NO_OWNERSHIP(HttpStatus.BAD_REQUEST.value(), 1251, "사용자의 물품이 아닙니다."), - RECEIVING_NOT_IN_TAKING(HttpStatus.BAD_REQUEST.value(), 1252,"입고요청서 상태가 절적하지 않습니다.") + RECEIVING_NOT_IN_TAKING(HttpStatus.BAD_REQUEST.value(), 1252,"입고 요청 상태가 아닙니다."), + RECEIVING_NOT_IN_CONFIRMATION(HttpStatus.NOT_FOUND.value(),1253,"입고 확정 상태가 아닙니다."), + RECEIVING_NOT_IN_DELIVERY(HttpStatus.NOT_FOUND.value(),1254,"입고 배송 상태가 아닙니다."), ; private final Integer httpCode; diff --git a/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java b/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java index 0e3892c1..7fd6b288 100644 --- a/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java +++ b/delivery/src/main/java/delivery/common/error/ShippingErrorCode.java @@ -10,7 +10,9 @@ public enum ShippingErrorCode implements ErrorCodeIfs { SHIPPING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1500, "출고 요청서가 존재하지 않습니다."), - SHIPPING_NOT_IN_PENDING(HttpStatus.NOT_FOUND.value(),1501,"출고 요청 상태가 아닙니다.") + SHIPPING_NOT_IN_PENDING(HttpStatus.NOT_FOUND.value(),1501,"출고 요청 상태가 아닙니다."), + SHIPPING_NOT_IN_REGISTERED(HttpStatus.NOT_FOUND.value(),1502,"출고 접수 상태가 아닙니다."), + SHIPPING_NOT_IN_DELIVERY(HttpStatus.NOT_FOUND.value(),1503,"출고 배송 상태가 아닙니다."), ; private final Integer httpCode; diff --git a/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java index 438ae5a0..82c1e29e 100644 --- a/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java +++ b/delivery/src/main/java/delivery/common/exception/GoodsExceptionHandler.java @@ -2,6 +2,9 @@ import delivery.common.error.GoodsErrorCode; import delivery.common.exception.goods.GoodsNotFoundException; +import delivery.common.exception.goods.GoodsNotInReceivingException; +import delivery.common.exception.goods.GoodsNotInShippingIngException; +import delivery.common.exception.goods.GoodsNotInStorageException; import delivery.common.exception.goods.InvalidGoodsStatusException; import delivery.common.exception.receiving.NotOwnerException; import global.api.Api; @@ -37,4 +40,25 @@ public ResponseEntity> notOwnerException(NotOwnerException e) { return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(Api.ERROR(GoodsErrorCode.NOT_OWNER)); } + + @ExceptionHandler(value = GoodsNotInStorageException.class) + public ResponseEntity> goodsNotInStorageException(GoodsNotInStorageException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(GoodsErrorCode.GOODS_NOT_IN_STORAGE)); + } + + @ExceptionHandler(value = GoodsNotInShippingIngException.class) + public ResponseEntity> goodsNotInShippingIngException(GoodsNotInShippingIngException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(GoodsErrorCode.GOODS_NOT_IN_SHIPPING_ING)); + } + + @ExceptionHandler(value = GoodsNotInReceivingException.class) + public ResponseEntity> goodsNotInReceivingException(GoodsNotInReceivingException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(GoodsErrorCode.GOODS_NOT_IN_RECEIVING)); + } } diff --git a/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java index a178b3af..cbe261c0 100644 --- a/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java +++ b/delivery/src/main/java/delivery/common/exception/ReceivingExceptionHandler.java @@ -3,6 +3,8 @@ import delivery.common.error.ReceivingErrorCode; import delivery.common.exception.receiving.NoOwnershipException; import delivery.common.exception.receiving.ReceivingNotFoundException; +import delivery.common.exception.receiving.ReceivingNotInConfirmationException; +import delivery.common.exception.receiving.ReceivingNotInDeliveryException; import delivery.common.exception.receiving.ReceivingNotInTakingException; import global.api.Api; import lombok.extern.slf4j.Slf4j; @@ -37,5 +39,19 @@ public ResponseEntity> receivingNotInTakingException(ReceivingNotInT return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(Api.ERROR(ReceivingErrorCode.RECEIVING_NOT_IN_TAKING)); } + + @ExceptionHandler(value = ReceivingNotInConfirmationException.class) + public ResponseEntity> receivingNotInConfirmationException(ReceivingNotInConfirmationException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(ReceivingErrorCode.RECEIVING_NOT_IN_CONFIRMATION)); + } + + @ExceptionHandler(value = ReceivingNotInDeliveryException.class) + public ResponseEntity> receivingNotInDeliveryException(ReceivingNotInDeliveryException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(Api.ERROR(ReceivingErrorCode.RECEIVING_NOT_IN_DELIVERY)); + } } diff --git a/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java b/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java index 1488d05d..7cdc1060 100644 --- a/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java +++ b/delivery/src/main/java/delivery/common/exception/ShippingExceptionHandler.java @@ -2,7 +2,9 @@ import delivery.common.error.ShippingErrorCode; import delivery.common.exception.shipping.ShippingNotFoundException; +import delivery.common.exception.shipping.ShippingNotInDeliveryException; import delivery.common.exception.shipping.ShippingNotInPendingException; +import delivery.common.exception.shipping.ShippingNotInRegisteredException; import global.api.Api; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -28,5 +30,18 @@ public ResponseEntity> shippingNotFoundException(ShippingNotInPendin .body(Api.ERROR(ShippingErrorCode.SHIPPING_NOT_IN_PENDING)); } + @ExceptionHandler(value = ShippingNotInRegisteredException.class) + public ResponseEntity> shippingNotInRegisteredException(ShippingNotInRegisteredException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(ShippingErrorCode.SHIPPING_NOT_IN_REGISTERED)); + } + + @ExceptionHandler(value = ShippingNotInDeliveryException.class) + public ResponseEntity> shippingNotInDeliveryException(ShippingNotInDeliveryException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(ShippingErrorCode.SHIPPING_NOT_IN_DELIVERY)); + } } diff --git a/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInReceivingException.java b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInReceivingException.java new file mode 100644 index 00000000..4548a2f9 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInReceivingException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsNotInReceivingException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsNotInReceivingException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInReceivingException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsNotInReceivingException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInReceivingException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInShippingIngException.java b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInShippingIngException.java new file mode 100644 index 00000000..425f80cb --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInShippingIngException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsNotInShippingIngException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsNotInShippingIngException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInShippingIngException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsNotInShippingIngException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInShippingIngException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInStorageException.java b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInStorageException.java new file mode 100644 index 00000000..f47b59cb --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/goods/GoodsNotInStorageException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.goods; + +import global.errorcode.ErrorCodeIfs; + +public class GoodsNotInStorageException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public GoodsNotInStorageException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInStorageException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public GoodsNotInStorageException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public GoodsNotInStorageException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInConfirmationException.java b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInConfirmationException.java new file mode 100644 index 00000000..ae30c65f --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInConfirmationException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.receiving; + +import global.errorcode.ErrorCodeIfs; + +public class ReceivingNotInConfirmationException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ReceivingNotInConfirmationException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotInConfirmationException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ReceivingNotInConfirmationException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotInConfirmationException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInDeliveryException.java b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInDeliveryException.java new file mode 100644 index 00000000..9f50ca0e --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/receiving/ReceivingNotInDeliveryException.java @@ -0,0 +1,36 @@ +package delivery.common.exception.receiving; + +import global.errorcode.ErrorCodeIfs; +import lombok.Getter; + +@Getter +public class ReceivingNotInDeliveryException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ReceivingNotInDeliveryException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ReceivingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ReceivingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInDeliveryException.java b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInDeliveryException.java new file mode 100644 index 00000000..be334966 --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInDeliveryException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.shipping; + +import global.errorcode.ErrorCodeIfs; + +public class ShippingNotInDeliveryException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ShippingNotInDeliveryException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ShippingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotInDeliveryException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInRegisteredException.java b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInRegisteredException.java new file mode 100644 index 00000000..d4d31f5e --- /dev/null +++ b/delivery/src/main/java/delivery/common/exception/shipping/ShippingNotInRegisteredException.java @@ -0,0 +1,34 @@ +package delivery.common.exception.shipping; + +import global.errorcode.ErrorCodeIfs; + +public class ShippingNotInRegisteredException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ShippingNotInRegisteredException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotInRegisteredException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ShippingNotInRegisteredException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotInRegisteredException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} \ No newline at end of file diff --git a/delivery/src/main/java/delivery/common/utils/datetime/DateTimeUtils.java b/delivery/src/main/java/delivery/common/utils/datetime/DateTimeUtils.java new file mode 100644 index 00000000..6a55231d --- /dev/null +++ b/delivery/src/main/java/delivery/common/utils/datetime/DateTimeUtils.java @@ -0,0 +1,37 @@ +package delivery.common.utils.datetime; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +public class DateTimeUtils { + + private static String startDate; + private static String dueDate; + private static DateTimeFormatter formatter; + + public static RequestDateTime getStartAndDueDate(String date){ + startDate = date + " 00:00:00.000"; + dueDate = date + " 23:59:59.999"; + formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + + return RequestDateTime.builder() + .startDateTime(LocalDateTime.parse(startDate, formatter)) + .dueDateTime(LocalDateTime.parse(dueDate, formatter)) + .build(); + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class RequestDateTime{ + private LocalDateTime startDateTime; + private LocalDateTime dueDateTime; + } +} diff --git a/delivery/src/main/java/delivery/domain/goods/business/GoodsBusiness.java b/delivery/src/main/java/delivery/domain/goods/business/GoodsBusiness.java new file mode 100644 index 00000000..1d908664 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/business/GoodsBusiness.java @@ -0,0 +1,65 @@ +package delivery.domain.goods.business; + +import db.domain.goods.GoodsEntity; +import db.domain.image.ImageEntity; +import db.domain.image.ImageRepository; +import delivery.domain.goods.controller.model.GoodsResponse; +import delivery.domain.goods.controller.model.GoodsResponses; +import delivery.domain.goods.controller.model.ImageSet; +import delivery.domain.goods.converter.GoodsConverter; +import delivery.domain.goods.service.GoodsService; +import delivery.domain.image.converter.ImageConverter; +import delivery.domain.image.service.ImageService; +import global.annotation.Business; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Business +@RequiredArgsConstructor +public class GoodsBusiness { + + private final GoodsService goodsService; + private final GoodsConverter goodsConverter; + private final ImageService imageService; + private final ImageConverter imageConverter; + private final ImageRepository imageRepository; + + public GoodsResponses getReceivingGoodsListBy(Long requestId) { + + List goodsEntityList = goodsService.getReceivingGoodsList(requestId); + + return setImageSet(goodsEntityList); + } + + public GoodsResponses getShippingGoodsListBy(Long requestId) { + + List goodsEntityList = goodsService.getShippingGoodsList(requestId); + + return setImageSet(goodsEntityList); + } + + private GoodsResponses setImageSet(List goodsEntityList) { + GoodsResponses responses = goodsConverter.toResponseList(goodsEntityList); + + responses.getGoodsResponseList().forEach(response -> { + log.info("goods id [{}] : goods Name [{}] ", response.getId(), response.getName()); + // GoodsImage Set Setting + List imageEntityList = imageService.getImageListBy(response.getId()); + List imageSet = imageConverter.toImageSetList(imageEntityList); + response.setImages(imageSet); + }); + + return responses; + } + + public GoodsResponse getGoodsBy(Long goodsId) { + GoodsEntity goodsEntity = goodsService.getGoodsBy(goodsId); + GoodsResponse response = goodsConverter.toResponse(goodsEntity); + List imageEntityList = imageService.getImageListBy(response.getId()); + List imageSet = imageConverter.toImageSetList(imageEntityList); + response.setImages(imageSet); + return response; + } +} diff --git a/delivery/src/main/java/delivery/domain/goods/controller/GoodsApiController.java b/delivery/src/main/java/delivery/domain/goods/controller/GoodsApiController.java new file mode 100644 index 00000000..875abaef --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/controller/GoodsApiController.java @@ -0,0 +1,42 @@ +package delivery.domain.goods.controller; + +import delivery.domain.goods.business.GoodsBusiness; +import delivery.domain.goods.controller.model.GoodsResponse; +import delivery.domain.goods.controller.model.GoodsResponses; +import global.api.Api; +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 +@RequiredArgsConstructor +@RequestMapping("/api/goods") +public class GoodsApiController { + + private final GoodsBusiness goodsBusiness; + + @GetMapping("/receiving/{requestId}") + public Api receivingGoods( + @PathVariable Long requestId + ){ + GoodsResponses response = goodsBusiness.getReceivingGoodsListBy(requestId); + return Api.OK(response); + } + + @GetMapping("/shipping/{requestId}") + public Api shippingGoods( + @PathVariable Long requestId + ){ + GoodsResponses response = goodsBusiness.getShippingGoodsListBy(requestId); + return Api.OK(response); + } + + @GetMapping("/{goodsId}") + public Api goodsById(@PathVariable Long goodsId){ + GoodsResponse response = goodsBusiness.getGoodsBy(goodsId); + return Api.OK(response); + } + +} diff --git a/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponse.java b/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponse.java new file mode 100644 index 00000000..f15fcf22 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponse.java @@ -0,0 +1,37 @@ +package delivery.domain.goods.controller.model; + +import db.domain.goods.enums.GoodsCategory; +import db.domain.goods.enums.GoodsStatus; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import java.time.LocalDateTime; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class GoodsResponse { + + private Long id; + + private String name; + + private String modelName; + + private GoodsCategory category; + + private int quantity; + + private LocalDateTime abandonmentAt; + + private GoodsStatus status; + + private List images; + +} diff --git a/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponses.java b/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponses.java new file mode 100644 index 00000000..e8c50ccc --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/controller/model/GoodsResponses.java @@ -0,0 +1,17 @@ +package delivery.domain.goods.controller.model; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class GoodsResponses { + + List goodsResponseList; + +} diff --git a/delivery/src/main/java/delivery/domain/goods/controller/model/ImageSet.java b/delivery/src/main/java/delivery/domain/goods/controller/model/ImageSet.java new file mode 100644 index 00000000..60090535 --- /dev/null +++ b/delivery/src/main/java/delivery/domain/goods/controller/model/ImageSet.java @@ -0,0 +1,19 @@ +package delivery.domain.goods.controller.model; + +import db.domain.image.enums.ImageKind; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ImageSet { + + private Long imageId; + private String caption; + private ImageKind kind; + +} diff --git a/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java b/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java index e9ae98ed..04fcbe3c 100644 --- a/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java +++ b/delivery/src/main/java/delivery/domain/goods/converter/GoodsConverter.java @@ -1,8 +1,33 @@ package delivery.domain.goods.converter; +import db.domain.goods.GoodsEntity; +import delivery.domain.goods.controller.model.GoodsResponse; +import delivery.domain.goods.controller.model.GoodsResponses; import global.annotation.Converter; +import java.util.List; @Converter public class GoodsConverter { + public GoodsResponses toResponseList(List goodsEntityList) { + List goodsResponses = goodsEntityList.stream().map(goodsEntity -> { + return toResponse(goodsEntity); + }).toList(); + return GoodsResponses.builder() + .goodsResponseList(goodsResponses) + .build(); + } + + public GoodsResponse toResponse(GoodsEntity goodsEntity) { + return GoodsResponse.builder() + .id(goodsEntity.getId()) + .name(goodsEntity.getName()) + .modelName(goodsEntity.getModelName()) + .status(goodsEntity.getStatus()) + .quantity(goodsEntity.getQuantity()) + .category(goodsEntity.getCategory()) + .abandonmentAt(goodsEntity.getAbandonmentAt()) + .build(); + } + } diff --git a/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java b/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java index d6edd7ed..86fc5d96 100644 --- a/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java +++ b/delivery/src/main/java/delivery/domain/goods/service/GoodsService.java @@ -2,6 +2,10 @@ import db.domain.goods.GoodsEntity; import db.domain.goods.GoodsRepository; +import db.domain.goods.enums.GoodsStatus; +import delivery.common.error.GoodsErrorCode; +import delivery.common.exception.goods.GoodsNotFoundException; +import delivery.common.exception.goods.GoodsNotInShippingIngException; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,4 +23,25 @@ public List getReceivingGoodsList(Long receivingId) { public List getShippingGoodsList(Long receivingId) { return goodsRepository.findAllByShippingIdOrderByIdDesc(receivingId); } + + public GoodsEntity getGoodsBy(Long goodsId) { + return goodsRepository.findById(goodsId).orElseThrow(() -> new GoodsNotFoundException( + GoodsErrorCode.GOODS_NOT_FOUND)); + } + + public GoodsEntity startShipping(GoodsEntity goodsEntity) { + goodsEntity.setStatus(GoodsStatus.SHIPPING_ING); + return goodsRepository.save(goodsEntity); + } + + public GoodsEntity changeShippingComplete(GoodsEntity goodsEntity) { + + if (goodsEntity.getStatus() != GoodsStatus.SHIPPING_ING){ + throw new GoodsNotInShippingIngException(GoodsErrorCode.GOODS_NOT_IN_SHIPPING_ING); + } + + goodsEntity.setStatus(GoodsStatus.SHIPPING); + return goodsRepository.save(goodsEntity); + } + } diff --git a/delivery/src/main/java/delivery/domain/image/converter/ImageConverter.java b/delivery/src/main/java/delivery/domain/image/converter/ImageConverter.java new file mode 100644 index 00000000..4c34a92a --- /dev/null +++ b/delivery/src/main/java/delivery/domain/image/converter/ImageConverter.java @@ -0,0 +1,26 @@ +package delivery.domain.image.converter; + +import db.domain.image.ImageEntity; +import delivery.domain.goods.controller.model.ImageSet; +import global.annotation.Converter; +import java.util.List; + +@Converter +public class ImageConverter { + + public List toImageSetList(List imageEntityList) { + return imageEntityList.stream().map(imageEntity -> { + return toImageSet(imageEntity); + }).toList(); + } + + public ImageSet toImageSet(ImageEntity imageEntity) { + return ImageSet.builder() + .imageId(imageEntity.getId()) + .caption(imageEntity.getCaption()) + .kind(imageEntity.getKind()) + .build(); + } + + +} diff --git a/delivery/src/main/java/delivery/domain/image/service/ImageService.java b/delivery/src/main/java/delivery/domain/image/service/ImageService.java new file mode 100644 index 00000000..544b9e9f --- /dev/null +++ b/delivery/src/main/java/delivery/domain/image/service/ImageService.java @@ -0,0 +1,19 @@ +package delivery.domain.image.service; + +import db.domain.image.ImageEntity; +import db.domain.image.ImageRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ImageService { + + private final ImageRepository imageRepository; + + public List getImageListBy(Long imageId) { + return imageRepository.findAllByGoodsIdOrderByIdDesc(imageId); + } + +} diff --git a/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java b/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java index 730de5f0..8133f524 100644 --- a/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java +++ b/delivery/src/main/java/delivery/domain/receiving/business/ReceivingBusiness.java @@ -1,8 +1,18 @@ package delivery.domain.receiving.business; import db.domain.goods.GoodsEntity; +import db.domain.goods.enums.GoodsStatus; import db.domain.receiving.ReceivingEntity; +import db.domain.receiving.enums.ReceivingStatus; import db.domain.users.UserEntity; +import delivery.common.error.GoodsErrorCode; +import delivery.common.error.ReceivingErrorCode; +import delivery.common.error.ShippingErrorCode; +import delivery.common.exception.goods.GoodsNotInReceivingException; +import delivery.common.exception.goods.GoodsNotInShippingIngException; +import delivery.common.exception.receiving.ReceivingNotInConfirmationException; +import delivery.common.utils.datetime.DateTimeUtils; +import delivery.common.utils.datetime.DateTimeUtils.RequestDateTime; import delivery.domain.goods.converter.GoodsConverter; import delivery.domain.goods.service.GoodsService; import delivery.domain.receiving.controller.model.ReceivingResponse; @@ -12,7 +22,6 @@ import delivery.domain.users.converter.UserConverter; import delivery.domain.users.service.UserService; import global.annotation.Business; -import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -34,26 +43,7 @@ public ReceivingResponseList getReservationList() { List receivingEntityList = receivingService.getRequestList(); - ReceivingResponseList responseList = receivingConverter.toResponseList(receivingEntityList); - - receivingEntityList.forEach(receivingEntity -> { - - log.info("receivingList Id : {} ", receivingEntity.getId()); - - List goodsIdList = goodsService.getReceivingGoodsList(receivingEntity.getId()) - .stream().map(goodsEntity -> { - return goodsEntity.getId(); - }).toList(); - - responseList.getReservationResponseList().forEach(reservationResponse -> { - reservationResponse.setGoodsIdList(goodsIdList); - reservationResponse.setUserName( - userService.getUserBy(receivingEntity.getUserId()).getName()); - }); - - }); - - return responseList; + return getResponseList(receivingEntityList); } public ReceivingResponse getReservation(Long requestId) { @@ -91,4 +81,74 @@ private ReceivingResponse setGoodsIdAndUserNameReceivingResponse( } + public ReceivingResponseList showReservationByDate(String date) { + + RequestDateTime dateTime = DateTimeUtils.getStartAndDueDate(date); + List receivingEntityList = receivingService.getRequestListByDate( + dateTime.getStartDateTime(), dateTime.getDueDateTime()); + + return getResponseList(receivingEntityList); + + } + + private ReceivingResponseList getResponseList(List receivingEntityList) { + ReceivingResponseList responseList = receivingConverter.toResponseList(receivingEntityList); + + receivingEntityList.forEach(receivingEntity -> { + + log.info("receivingList Id : {} ", receivingEntity.getId()); + + List goodsIdList = goodsService.getReceivingGoodsList(receivingEntity.getId()) + .stream().map(goodsEntity -> { + return goodsEntity.getId(); + }).toList(); + + responseList.getReservationResponseList().forEach(reservationResponse -> { + reservationResponse.setGoodsIdList(goodsIdList); + reservationResponse.setUserName( + userService.getUserBy(receivingEntity.getUserId()).getName()); + }); + + }); + + return responseList; + } + + public ReceivingResponse deliveryStart(Long requestId) { + + ReceivingEntity receivingEntity = receivingService.getRequestBy(requestId); + + if (receivingEntity.getStatus() != ReceivingStatus.CONFIRMATION) { + throw new ReceivingNotInConfirmationException( + ReceivingErrorCode.RECEIVING_NOT_IN_CONFIRMATION); + } + + ReceivingEntity updateEntity = receivingService.startDelivery(receivingEntity); + + ReceivingResponse receivingResponse = setGoodsIdAndUserNameReceivingResponse(updateEntity); + + receivingResponse.getGoodsIdList().forEach(goodsId -> { + GoodsEntity goodsEntity = goodsService.getGoodsBy(goodsId); + if (goodsEntity.getStatus() != GoodsStatus.RECEIVING){ + throw new GoodsNotInReceivingException(GoodsErrorCode.GOODS_NOT_IN_RECEIVING); + } + }); + + return receivingResponse; + } + + public ReceivingResponse deliveryComplete(Long requestId) { + + ReceivingEntity receivingEntity = receivingService.getRequestBy(requestId); + + if (receivingEntity.getStatus() != ReceivingStatus.DELIVERY) { + throw new ReceivingNotInConfirmationException( + ReceivingErrorCode.RECEIVING_NOT_IN_CONFIRMATION); + } + + ReceivingEntity updateEntity = receivingService.deliveryComplete(receivingEntity); + + return setGoodsIdAndUserNameReceivingResponse(updateEntity); + + } } diff --git a/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java b/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java index 50172a07..b27d8ab6 100644 --- a/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java +++ b/delivery/src/main/java/delivery/domain/receiving/controller/ReceivingApiController.java @@ -4,11 +4,14 @@ import delivery.domain.receiving.controller.model.ReceivingResponse; import delivery.domain.receiving.controller.model.ReceivingResponseList; import global.api.Api; +import java.time.LocalDate; +import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -19,13 +22,13 @@ public class ReceivingApiController { private final ReceivingBusiness receivingBusiness; @GetMapping - public Api showReservationList(){ + public Api showReservationList() { ReceivingResponseList response = receivingBusiness.getReservationList(); return Api.OK(response); } @GetMapping("/{requestId}") - public Api showReservation(@PathVariable Long requestId){ + public Api showReservation(@PathVariable Long requestId) { ReceivingResponse response = receivingBusiness.getReservation(requestId); return Api.OK(response); } @@ -33,9 +36,32 @@ public Api showReservation(@PathVariable Long requestId){ @PostMapping("/reservation/{requestId}") public Api receivingReservation( @PathVariable Long requestId - ){ + ) { ReceivingResponse response = receivingBusiness.reservationConfirmed(requestId); return Api.OK(response); } + // TODO Login DeliveryMan 정보 활용 필요 + @GetMapping("/reservation") + public Api showReservationByDate( + @RequestParam String date + ) { + ReceivingResponseList response = receivingBusiness.showReservationByDate(date); + return Api.OK(response); + } + + // TODO Login DeliveryMan 정보 활용 필요 + @PostMapping("/start/{requestId}") + public Api deliveryStart(@PathVariable Long requestId) { + ReceivingResponse response = receivingBusiness.deliveryStart(requestId); + return Api.OK(response); + } + + // TODO Login DeliveryMan 정보 활용 필요 + @PostMapping("/complete/{requestId}") + public Api deliveryComplete(@PathVariable Long requestId) { + ReceivingResponse response = receivingBusiness.deliveryComplete(requestId); + return Api.OK(response); + } + } diff --git a/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java b/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java index 80e2f1a8..1ea57597 100644 --- a/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java +++ b/delivery/src/main/java/delivery/domain/receiving/service/ReceivingService.java @@ -7,6 +7,7 @@ import delivery.common.exception.receiving.ReceivingNotFoundException; import delivery.common.exception.receiving.ReceivingNotInTakingException; import delivery.domain.receiving.controller.model.ReceivingResponse; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -46,4 +47,24 @@ public ReceivingEntity reservationConfirmed(Long requestId) { receivingEntity.setStatus(ReceivingStatus.CONFIRMATION); return receivingRepository.save(receivingEntity); } + + public List getRequestListByDate(LocalDateTime startDate,LocalDateTime dueDate) { + List receivingEntityList = receivingRepository.findAllByStatusAndVisitDateBetweenOrderByUserId( + ReceivingStatus.CONFIRMATION, startDate, dueDate); + + if (receivingEntityList.isEmpty()) { + throw new ReceivingNotFoundException(ReceivingErrorCode.RECEIVING_REQUEST_NOT_FOUND); + } + return receivingEntityList; + } + + public ReceivingEntity startDelivery(ReceivingEntity receivingEntity) { + receivingEntity.setStatus(ReceivingStatus.DELIVERY); + return receivingRepository.save(receivingEntity); + } + + public ReceivingEntity deliveryComplete(ReceivingEntity receivingEntity) { + receivingEntity.setStatus(ReceivingStatus.RECEIVING); + return receivingRepository.save(receivingEntity); + } } diff --git a/delivery/src/main/java/delivery/domain/shipping/business/ShippingBusiness.java b/delivery/src/main/java/delivery/domain/shipping/business/ShippingBusiness.java index 1c7ddd38..67bc8047 100644 --- a/delivery/src/main/java/delivery/domain/shipping/business/ShippingBusiness.java +++ b/delivery/src/main/java/delivery/domain/shipping/business/ShippingBusiness.java @@ -1,10 +1,25 @@ package delivery.domain.shipping.business; +import db.domain.goods.GoodsEntity; +import db.domain.goods.enums.GoodsStatus; import db.domain.receiving.ReceivingEntity; +import db.domain.receiving.enums.ReceivingStatus; import db.domain.shipping.ShippingEntity; +import db.domain.shipping.enums.ShippingStatus; import db.domain.users.UserEntity; +import delivery.common.error.GoodsErrorCode; +import delivery.common.error.ReceivingErrorCode; +import delivery.common.error.ShippingErrorCode; +import delivery.common.exception.goods.GoodsNotFoundException; +import delivery.common.exception.goods.GoodsNotInShippingIngException; +import delivery.common.exception.goods.GoodsNotInStorageException; +import delivery.common.exception.receiving.ReceivingNotInConfirmationException; +import delivery.common.exception.shipping.ShippingNotInRegisteredException; +import delivery.common.utils.datetime.DateTimeUtils; +import delivery.common.utils.datetime.DateTimeUtils.RequestDateTime; import delivery.domain.goods.converter.GoodsConverter; import delivery.domain.goods.service.GoodsService; +import delivery.domain.receiving.controller.model.ReceivingResponse; import delivery.domain.receiving.controller.model.ReceivingResponseList; import delivery.domain.shipping.controller.model.ShippingResponse; import delivery.domain.shipping.controller.model.ShippingResponseList; @@ -14,6 +29,7 @@ import delivery.domain.users.service.UserService; import global.annotation.Business; import java.util.List; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,6 +49,52 @@ public ShippingResponseList getReservationList() { List shippingEntityList = shippingService.getRequestList(); + return getResponseList(shippingEntityList); + } + + public ShippingResponse getReservation(Long requestId) { + ShippingEntity shippingEntity = shippingService.getRequest(requestId); + + ShippingResponse response = getShippingResponse(shippingEntity); + + return response; + } + + public ShippingResponse shippingReservation(Long requestId) { + ShippingEntity shippingEntity = shippingService.reservationConfirmed(requestId); + + ShippingResponse response = getShippingResponse(shippingEntity); + + return response; + } + + private ShippingResponse getShippingResponse(ShippingEntity shippingEntity) { + ShippingResponse response = shippingConverter.toResponse(shippingEntity); + + List goodsIdList = goodsService.getShippingGoodsList(shippingEntity.getId()).stream().map( + goodsEntity -> { + return goodsEntity.getId(); + } + ).toList(); + + UserEntity userEntity = userService.getUserBy(shippingEntity.getUserId()); + + response.setUserName(userEntity.getName()); + response.setGoodsIdList(goodsIdList); + + return response; + } + + public ShippingResponseList showReservationByDate(String date) { + + RequestDateTime dateTime = DateTimeUtils.getStartAndDueDate(date); + + List shippingEntityList = shippingService.getRequestListByDate(dateTime.getStartDateTime(),dateTime.getDueDateTime()); + + return getResponseList(shippingEntityList); + } + + private ShippingResponseList getResponseList(List shippingEntityList) { ShippingResponseList responseList = shippingConverter.toResponseList(shippingEntityList); shippingEntityList.forEach(shippingEntity -> { @@ -53,39 +115,50 @@ public ShippingResponseList getReservationList() { }); return responseList; - } - public ShippingResponse getReservation(Long requestId) { + public ShippingResponse deliveryStart(Long requestId) { + ShippingEntity shippingEntity = shippingService.getRequest(requestId); - ShippingResponse response = getShippingResponse(shippingEntity); + if (shippingEntity.getStatus() != ShippingStatus.REGISTERED) { + throw new ShippingNotInRegisteredException( + ShippingErrorCode.SHIPPING_NOT_IN_REGISTERED); + } - return response; - } + ShippingEntity updateEntity = shippingService.startDelivery(shippingEntity); - public ShippingResponse shippingReservation(Long requestId) { - ShippingEntity shippingEntity = shippingService.reservationConfirmed(requestId); + ShippingResponse shippingResponse = getShippingResponse(updateEntity); - ShippingResponse response = getShippingResponse(shippingEntity); + shippingResponse.getGoodsIdList().forEach(goodsId -> { + GoodsEntity goodsEntity = goodsService.getGoodsBy(goodsId); + if (goodsEntity.getStatus() != GoodsStatus.SHIPPING_ING){ + throw new GoodsNotInShippingIngException(GoodsErrorCode.GOODS_NOT_IN_SHIPPING_ING); + } + }); - return response; + return shippingResponse; } - private ShippingResponse getShippingResponse(ShippingEntity shippingEntity) { - ShippingResponse response = shippingConverter.toResponse(shippingEntity); + public ShippingResponse deliveryComplete(Long requestId) { - List goodsIdList = goodsService.getShippingGoodsList(shippingEntity.getId()).stream().map( - goodsEntity -> { - return goodsEntity.getId(); - } - ).toList(); + ShippingEntity shippingEntity = shippingService.getRequest(requestId); - UserEntity userEntity = userService.getUserBy(shippingEntity.getUserId()); + if (shippingEntity.getStatus() != ShippingStatus.DELIVERY) { + throw new ShippingNotInRegisteredException( + ShippingErrorCode.SHIPPING_NOT_IN_DELIVERY); + } - response.setUserName(userEntity.getName()); - response.setGoodsIdList(goodsIdList); + ShippingEntity updateEntity = shippingService.deliveryComplete(shippingEntity); + + ShippingResponse shippingResponse = getShippingResponse(updateEntity); + + shippingResponse.getGoodsIdList().forEach(goodsId -> { + GoodsEntity goodsEntity = goodsService.getGoodsBy(goodsId); + goodsService.changeShippingComplete(goodsEntity); + }); + + return shippingResponse; - return response; } } diff --git a/delivery/src/main/java/delivery/domain/shipping/controller/ShippingApiController.java b/delivery/src/main/java/delivery/domain/shipping/controller/ShippingApiController.java index 4f67e31d..fab26308 100644 --- a/delivery/src/main/java/delivery/domain/shipping/controller/ShippingApiController.java +++ b/delivery/src/main/java/delivery/domain/shipping/controller/ShippingApiController.java @@ -1,5 +1,6 @@ package delivery.domain.shipping.controller; +import delivery.domain.receiving.controller.model.ReceivingResponse; import delivery.domain.receiving.controller.model.ReceivingResponseList; import delivery.domain.shipping.business.ShippingBusiness; import delivery.domain.shipping.controller.model.ShippingResponse; @@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -39,4 +41,28 @@ public Api shippingReservation( return Api.OK(response); } + // TODO Login DeliveryMan 정보 활용 필요 + @GetMapping("/reservation") + public Api showReservationByDate( + @RequestParam String date + ){ + ShippingResponseList response = shippingBusiness.showReservationByDate(date); + return Api.OK(response); + } + + // TODO Login DeliveryMan 정보 활용 필요 + @PostMapping("/start/{requestId}") + public Api deliveryStart(@PathVariable Long requestId) { + ShippingResponse response = shippingBusiness.deliveryStart(requestId); + return Api.OK(response); + } + + // TODO Login DeliveryMan 정보 활용 필요 + @PostMapping("/complete/{requestId}") + public Api deliveryComplete(@PathVariable Long requestId) { + ShippingResponse response = shippingBusiness.deliveryComplete(requestId); + return Api.OK(response); + } + + } diff --git a/delivery/src/main/java/delivery/domain/shipping/service/ShippingService.java b/delivery/src/main/java/delivery/domain/shipping/service/ShippingService.java index d8df77d7..fd538528 100644 --- a/delivery/src/main/java/delivery/domain/shipping/service/ShippingService.java +++ b/delivery/src/main/java/delivery/domain/shipping/service/ShippingService.java @@ -5,9 +5,12 @@ import db.domain.shipping.ShippingEntity; import db.domain.shipping.ShippingRepository; import db.domain.shipping.enums.ShippingStatus; +import delivery.common.error.ReceivingErrorCode; import delivery.common.error.ShippingErrorCode; +import delivery.common.exception.receiving.ReceivingNotFoundException; import delivery.common.exception.shipping.ShippingNotFoundException; import delivery.common.exception.shipping.ShippingNotInPendingException; +import java.time.LocalDateTime; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -48,4 +51,24 @@ public ShippingEntity reservationConfirmed(Long requestId) { return shippingRepository.save(shippingEntity); } + + public List getRequestListByDate(LocalDateTime startDate, LocalDateTime dueDate) { + List receivingEntityList = shippingRepository.findAllByStatusAndDeliveryDateBetweenOrderByUserId( + ShippingStatus.REGISTERED, startDate, dueDate); + + if (receivingEntityList.isEmpty()) { + throw new ReceivingNotFoundException(ReceivingErrorCode.RECEIVING_REQUEST_NOT_FOUND); + } + return receivingEntityList; + } + + public ShippingEntity startDelivery(ShippingEntity shippingEntity) { + shippingEntity.setStatus(ShippingStatus.DELIVERY); + return shippingRepository.save(shippingEntity); + } + + public ShippingEntity deliveryComplete(ShippingEntity shippingEntity) { + shippingEntity.setStatus(ShippingStatus.SHIPPED); + return shippingRepository.save(shippingEntity); + } } diff --git a/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java b/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java index 069373fe..fe43a53a 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java +++ b/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java @@ -46,25 +46,25 @@ public List getGoodsList(GetGoodsStrategy strategy, Long requestI List goodsList = findGoodsListById(strategy, requestId, email); - return getGoodsResponsesBy(goodsList, email); + return getGoodsResponsesBy(goodsList); } @Transactional public List getGoodsList(GoodsStatus status, String email) { - List goodsList = goodsService.findAllByGoodsStatusWithThrow(status); + Long userId = usersService.getUserWithThrow(email).getId(); - return getGoodsResponsesBy(goodsList, email); + List goodsList = goodsService.findAllByGoodsStatusAndUserIdWithThrow(status ,userId); + + return getGoodsResponsesBy(goodsList); } - private List getGoodsResponsesBy(List goodsList, String email) { + private List getGoodsResponsesBy(List goodsList) { List goodsResponse = new ArrayList<>(); goodsList.forEach(goodsEntity -> { - goodsOwnerCheckWithThrow(email, goodsEntity); - ImageListResponse imageListResponse = imageConverter.toImageListResponse(goodsEntity); goodsResponse.add(goodsConverter.toResponse(goodsEntity, imageListResponse)); @@ -74,13 +74,6 @@ private List getGoodsResponsesBy(List goodsList, Str return goodsResponse; } - private void goodsOwnerCheckWithThrow(String email, GoodsEntity goodsEntity) { - UserEntity userEntity = usersService.getUserWithThrow(email); - if (!Objects.equals(userEntity.getId(), goodsEntity.getUserId())) { - throw new NotOwnerException(GoodsErrorCode.NOT_OWNER); - } - } - private List findGoodsListById(GetGoodsStrategy strategy, Long requestId, String email) { switch (strategy) { diff --git a/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java b/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java index ca7ef9c9..7ac19d4c 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java +++ b/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java @@ -104,8 +104,8 @@ private void setGoodsStatusBy(GoodsStatus status, GoodsEntity goodsEntity) { goodsRepository.save(goodsEntity); } - public List findAllByGoodsStatusWithThrow(GoodsStatus status) { - List goodsEntityList = goodsRepository.findAllByStatusOrderByIdDesc(status); + public List findAllByGoodsStatusAndUserIdWithThrow(GoodsStatus status, Long userId) { + List goodsEntityList = goodsRepository.findAllByStatusAndUserIdOrderByIdDesc(status, userId); checkEmptyGoodsListWithThrow(goodsEntityList); return goodsEntityList; } diff --git a/warehouse/src/main/java/warehouse/domain/users/controller/model/register/UsersRegisterRequest.java b/warehouse/src/main/java/warehouse/domain/users/controller/model/register/UsersRegisterRequest.java index 40962cad..43f69868 100644 --- a/warehouse/src/main/java/warehouse/domain/users/controller/model/register/UsersRegisterRequest.java +++ b/warehouse/src/main/java/warehouse/domain/users/controller/model/register/UsersRegisterRequest.java @@ -18,7 +18,7 @@ public class UsersRegisterRequest { @Pattern(regexp = "^[0-9a-zA-Z]{1,50}@[0-9a-zA-Z]{1,24}+(\\.[0-9a-zA-Z]+){1,24}$") private String email; - @Pattern(regexp = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9])(?!.*[\\\\{}()<>#$%^&*_=|~`]).{8,100}$") + @Pattern(regexp = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9])(?!.*[\\\\{}()<>$%^&*_=|`]).{8,100}$") private String password; @Pattern(regexp = "^[가-힣]{1,50}$")