diff --git a/db/src/main/java/db/domain/goods/GoodsEntity.java b/db/src/main/java/db/domain/goods/GoodsEntity.java index be1cbd2e..a9a6187e 100644 --- a/db/src/main/java/db/domain/goods/GoodsEntity.java +++ b/db/src/main/java/db/domain/goods/GoodsEntity.java @@ -52,4 +52,6 @@ public class GoodsEntity extends BaseEntity { @Column(length = 50, nullable = false, columnDefinition = "VARCHAR(50)") private GoodsStatus status; + private Long shippingId; + } diff --git a/db/src/main/java/db/domain/goods/GoodsRepository.java b/db/src/main/java/db/domain/goods/GoodsRepository.java index 7d635bdb..3b017f23 100644 --- a/db/src/main/java/db/domain/goods/GoodsRepository.java +++ b/db/src/main/java/db/domain/goods/GoodsRepository.java @@ -18,7 +18,6 @@ public interface GoodsRepository extends JpaRepository { List findAllByTakeBackIdOrderByIdDesc(Long takeBackId); - //TODO 출고 시스템 완료 후 구현 예정 - //List findAllByShippingIdOrderByIdDesc(Long takeBackId); + List findAllByShippingIdOrderByIdDesc(Long takeBackId); } diff --git a/db/src/main/java/db/domain/shipping/ShippingEntity.java b/db/src/main/java/db/domain/shipping/ShippingEntity.java new file mode 100644 index 00000000..57032575 --- /dev/null +++ b/db/src/main/java/db/domain/shipping/ShippingEntity.java @@ -0,0 +1,40 @@ +package db.domain.shipping; + +import db.common.BaseEntity; +import db.domain.shipping.enums.ShippingStatus; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@EqualsAndHashCode(callSuper = true) +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "shipping") +@SuperBuilder +public class ShippingEntity extends BaseEntity { + + private LocalDateTime deliveryDate; + + @Column(nullable = false, length = 200) + private String deliveryAddress; + + @Enumerated(EnumType.STRING) + @Column(length = 50, nullable = false, columnDefinition = "VARCHAR(50)") + private ShippingStatus status; + + @Column(nullable = false) + private Long userId; + + private Long deliveryMan; + +} diff --git a/db/src/main/java/db/domain/shipping/ShippingRepository.java b/db/src/main/java/db/domain/shipping/ShippingRepository.java new file mode 100644 index 00000000..11c4da66 --- /dev/null +++ b/db/src/main/java/db/domain/shipping/ShippingRepository.java @@ -0,0 +1,13 @@ +package db.domain.shipping; + +import java.util.List; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ShippingRepository extends JpaRepository { + + List findAllByUserIdOrderByIdDesc(Long userId); + + Optional findFirstById(Long shippingId); + +} diff --git a/db/src/main/java/db/domain/shipping/enums/ShippingStatus.java b/db/src/main/java/db/domain/shipping/enums/ShippingStatus.java new file mode 100644 index 00000000..4790fc44 --- /dev/null +++ b/db/src/main/java/db/domain/shipping/enums/ShippingStatus.java @@ -0,0 +1,22 @@ +package db.domain.shipping.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ShippingStatus { + + PENDING(1,"출고 대기 중","출고 대기 중 입니다."), + REGISTERED(2,"출고 접수 완료", "출고 일정이 확정되었습니다."), + DELIVERY(3,"출고 중","물건을 안전하게 출고 중입니다."), + SHIPPED(4,"출고 완료", "물건이 지정된 장소에 도착하였습니다."), + CLOSE(5, "CLOSE", "요청이 닫힌 상태입니다.") + ; + + private final int current; + private final String status; + private final String description; + +} + diff --git a/warehouse/src/main/java/warehouse/common/error/ShippingErrorCode.java b/warehouse/src/main/java/warehouse/common/error/ShippingErrorCode.java new file mode 100644 index 00000000..943e5343 --- /dev/null +++ b/warehouse/src/main/java/warehouse/common/error/ShippingErrorCode.java @@ -0,0 +1,18 @@ +package warehouse.common.error; + +import global.errorcode.ErrorCodeIfs; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ShippingErrorCode implements ErrorCodeIfs { + + SHIPPING_REQUEST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1500, "출고 요청서가 존재하지 않습니다.") + ; + + private final Integer httpCode; + private final Integer errorCode; + private final String description; +} diff --git a/warehouse/src/main/java/warehouse/common/exception/Goods/InvalidGoodsStatusException.java b/warehouse/src/main/java/warehouse/common/exception/Goods/InvalidGoodsStatusException.java index 48d650c0..896f4dc2 100644 --- a/warehouse/src/main/java/warehouse/common/exception/Goods/InvalidGoodsStatusException.java +++ b/warehouse/src/main/java/warehouse/common/exception/Goods/InvalidGoodsStatusException.java @@ -1,4 +1,4 @@ -package warehouse.common.exception.goods; +package warehouse.common.exception.Goods; import global.errorcode.ErrorCodeIfs; diff --git a/warehouse/src/main/java/warehouse/common/exception/GoodsExceptionHandler.java b/warehouse/src/main/java/warehouse/common/exception/GoodsExceptionHandler.java index 148f4fd6..bdcbac2d 100644 --- a/warehouse/src/main/java/warehouse/common/exception/GoodsExceptionHandler.java +++ b/warehouse/src/main/java/warehouse/common/exception/GoodsExceptionHandler.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import warehouse.common.error.GoodsErrorCode; -import warehouse.common.exception.goods.InvalidGoodsStatusException; +import warehouse.common.exception.Goods.InvalidGoodsStatusException; import warehouse.common.exception.goods.GoodsNotFoundException; @Slf4j @@ -24,8 +24,7 @@ public ResponseEntity> imageException(GoodsNotFoundException e) { } @ExceptionHandler(value = InvalidGoodsStatusException.class) - public ResponseEntity> InvalidGoodsStatus( - warehouse.common.exception.goods.InvalidGoodsStatusException e) { + public ResponseEntity> InvalidGoodsStatus(InvalidGoodsStatusException e) { log.info("", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(Api.ERROR(GoodsErrorCode.INVALID_GOODS_STATUS)); diff --git a/warehouse/src/main/java/warehouse/common/exception/ShippingExceptionHandler.java b/warehouse/src/main/java/warehouse/common/exception/ShippingExceptionHandler.java new file mode 100644 index 00000000..a7d58ae1 --- /dev/null +++ b/warehouse/src/main/java/warehouse/common/exception/ShippingExceptionHandler.java @@ -0,0 +1,23 @@ +package warehouse.common.exception; + +import global.api.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import warehouse.common.error.ShippingErrorCode; +import warehouse.common.exception.shipping.ShippingNotFoundException; + +@Slf4j +@RestControllerAdvice +public class ShippingExceptionHandler { + + @ExceptionHandler(value = ShippingNotFoundException.class) + public ResponseEntity> shippingNotFoundException(ShippingNotFoundException e) { + log.info("", e); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Api.ERROR(ShippingErrorCode.SHIPPING_REQUEST_NOT_FOUND)); + } + +} diff --git a/warehouse/src/main/java/warehouse/common/exception/shipping/ShippingNotFoundException.java b/warehouse/src/main/java/warehouse/common/exception/shipping/ShippingNotFoundException.java new file mode 100644 index 00000000..c04b974d --- /dev/null +++ b/warehouse/src/main/java/warehouse/common/exception/shipping/ShippingNotFoundException.java @@ -0,0 +1,34 @@ +package warehouse.common.exception.shipping; + +import global.errorcode.ErrorCodeIfs; + +public class ShippingNotFoundException extends RuntimeException { + + private final ErrorCodeIfs errorCodeIfs; + private final String description; + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs) { + super(errorCodeIfs.getDescription()); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, String errorDescription) { + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorCodeIfs.getDescription(); + } + + public ShippingNotFoundException(ErrorCodeIfs errorCodeIfs, Throwable throwable, + String errorDescription) { + super(throwable); + this.errorCodeIfs = errorCodeIfs; + this.description = errorDescription; + } + +} 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 5aadb31f..6240e26c 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java +++ b/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java @@ -29,23 +29,23 @@ public class GoodsBusiness { private final ImageService imageService; private final ImageConverter imageConverter; - public List> getGoodsList(GetGoodsStrategy strategy,Long requestId) { + public List getGoodsList(GetGoodsStrategy strategy,Long requestId) { List goodsList = findGoodsListById(strategy,requestId); return getGoodsResponsesBy(goodsList); } - public List> getGoodsList(GoodsStatus status) { + public List getGoodsList(GoodsStatus status) { List goodsList = goodsService.findAllByGoodsStatusWithThrow(status); return getGoodsResponsesBy(goodsList); } - private List> getGoodsResponsesBy(List goodsList) { + private List getGoodsResponsesBy(List goodsList) { - List> goodsResponse = new ArrayList<>(); + List goodsResponse = new ArrayList<>(); goodsList.forEach(goodsEntity -> { @@ -63,7 +63,7 @@ private List> getGoodsResponsesBy(List goodsLis ImageListResponse imageListResponse = imageConverter.toImageListResponse(basicList, faultList); - goodsResponse.add(goodsConverter.toResponseListBy(goodsList, imageListResponse)); + goodsResponse.add(goodsConverter.toResponse(goodsEntity, imageListResponse)); }); diff --git a/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java b/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java index 22a3267d..3c55ff86 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java +++ b/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java @@ -21,14 +21,14 @@ public class GoodsController { private final GoodsBusiness goodsBusiness; @GetMapping("/{strategy}/{requestId}") - public Api>> receiving(@PathVariable GetGoodsStrategy strategy, @PathVariable Long requestId) { - List> response = goodsBusiness.getGoodsList(strategy,requestId); + public Api> receiving(@PathVariable GetGoodsStrategy strategy, @PathVariable Long requestId) { + List response = goodsBusiness.getGoodsList(strategy,requestId); return Api.OK(response); } @GetMapping() - public Api>> getGoodsByStatus(@RequestParam GoodsStatus status) { - List> response = goodsBusiness.getGoodsList(status); + public Api> getGoodsByStatus(@RequestParam GoodsStatus status) { + List response = goodsBusiness.getGoodsList(status); return Api.OK(response); } 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 27c63f2d..8e8d45df 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java +++ b/warehouse/src/main/java/warehouse/domain/goods/service/GoodsService.java @@ -10,8 +10,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import warehouse.common.error.GoodsErrorCode; +import warehouse.common.exception.Goods.InvalidGoodsStatusException; import warehouse.common.exception.goods.GoodsNotFoundException; -import warehouse.common.exception.goods.InvalidGoodsStatusException; @Service @RequiredArgsConstructor @@ -133,8 +133,7 @@ public List findAllByTakeBackIdWithThrow(Long takeBackId) { return goodsEntityList; } - //TODO 출고 시스템 완료 후 구현 예정 - /*public List findAllByShippingIdWithThrow(Long shippingId) { + public List findAllByShippingIdWithThrow(Long shippingId) { List goodsEntityList = goodsRepository.findAllByShippingIdOrderByIdDesc( shippingId); @@ -143,6 +142,13 @@ public List findAllByTakeBackIdWithThrow(Long takeBackId) { throw new GoodsNotFoundException(GoodsErrorCode.GOODS_NOT_FOUND); } return goodsEntityList; - }*/ + } + + public void setShippingId(List goodsEntityList, Long shippingId) { + goodsEntityList.forEach(goodsEntity -> { + goodsEntity.setShippingId(shippingId); + goodsRepository.save(goodsEntity); + }); + } } \ No newline at end of file diff --git a/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java new file mode 100644 index 00000000..30a379ec --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java @@ -0,0 +1,105 @@ +package warehouse.domain.shipping.business; + +import db.domain.goods.GoodsEntity; +import db.domain.goods.enums.GoodsStatus; +import db.domain.image.ImageEntity; +import db.domain.image.enums.ImageKind; +import db.domain.shipping.ShippingEntity; +import global.annotation.Business; +import java.util.List; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import warehouse.domain.goods.controller.model.GoodsResponse; +import warehouse.domain.goods.converter.GoodsConverter; +import warehouse.domain.goods.service.GoodsService; +import warehouse.domain.image.controller.model.ImageListResponse; +import warehouse.domain.image.converter.ImageConverter; +import warehouse.domain.image.service.ImageService; +import warehouse.domain.shipping.controller.model.request.ShippingRequest; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; +import warehouse.domain.shipping.controller.model.response.ShippingListResponse; +import warehouse.domain.shipping.controller.model.response.MessageResponse; +import warehouse.domain.shipping.controller.model.response.ShippingResponse; +import warehouse.domain.shipping.converter.ShippingConverter; +import warehouse.domain.shipping.service.ShippingService; +import warehouse.domain.users.service.UsersService; + +@Business +@RequiredArgsConstructor +public class ShippingBusiness { + + private final UsersService usersService; + private final GoodsService goodsService; + private final ShippingService shippingService; + private final ImageService imageService; + private final ShippingConverter shippingConverter; + private final GoodsConverter goodsConverter; + private final ImageConverter imageConverter; + + + public MessageResponse shippingRequest(ShippingRequest request, String email) { + + // 상품이 STORAGE 인지 확인 + goodsService.checkStoredGoodsAndStatusWithThrowBy(request.getGoodsIdList(), + GoodsStatus.STORAGE); + + Long userId = usersService.getUserWithThrow(email).getId(); + + ShippingEntity shippingEntity = shippingConverter.toEntity(request); + + ShippingEntity savedShippingEntity = shippingService.shippingRequest(shippingEntity, userId); + + // GoodsStatus 를 SHIPPING_ING 으로 변경 + goodsService.setGoodsStatusBy(request.getGoodsIdList(), GoodsStatus.SHIPPING_ING); + + List goodsEntityList = goodsService.getGoodsListBy(request.getGoodsIdList()); + + // goods 컬럼에 shipping_id 부여 + goodsService.setShippingId(goodsEntityList, savedShippingEntity.getId()); + + return shippingConverter.toMessageResponse("출고 신청이 완료되었습니다."); + + } + + + public ShippingListResponse getShippingList(String email) { + + Long userId = usersService.getUserWithThrow(email).getId(); + + List shippingEntityList = shippingService.getShippingList(userId); + + return shippingConverter.toResponseList(shippingEntityList); + + } + + public ShippingDetailResponse getShippingDetail(Long shippingId) { + + ShippingEntity shippingEntity = shippingService.getShippingDetail(shippingId); + + ShippingResponse shippingResponse = shippingConverter.toResponse(shippingEntity); + + List goodsIdList = goodsService.findAllByShippingIdWithThrow(shippingId).stream() + .map(entity -> entity.getId()).collect(Collectors.toList()); + + List goodsEntityList = goodsService.getGoodsListBy(goodsIdList); + + List goodsResponse = goodsEntityList.stream() + .map(entity -> getGoodsResponse(entity)).collect(Collectors.toList()); + + return shippingConverter.toResponse(shippingResponse, goodsResponse); + + } + + + private GoodsResponse getGoodsResponse(GoodsEntity goodsEntity) { + List basicImageEntityList = imageService.getImageUrlListBy(goodsEntity.getId(), + ImageKind.BASIC); + List faultImageEntityList = imageService.getImageUrlListBy(goodsEntity.getId(), + ImageKind.FAULT); + ImageListResponse imageListResponse = imageConverter.toImageListResponse( + basicImageEntityList, faultImageEntityList); + return goodsConverter.toResponse(goodsEntity, imageListResponse); + } + + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java new file mode 100644 index 00000000..f535a6c2 --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java @@ -0,0 +1,47 @@ +package warehouse.domain.shipping.controller; + +import global.annotation.ApiValid; +import global.api.Api; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.User; +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.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import warehouse.domain.shipping.business.ShippingBusiness; +import warehouse.domain.shipping.controller.model.request.ShippingRequest; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; +import warehouse.domain.shipping.controller.model.response.ShippingListResponse; +import warehouse.domain.shipping.controller.model.response.MessageResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/shipping") +public class ShippingApiController { + + private final ShippingBusiness shippingBusiness; + + @PostMapping() + public Api shippingRequest(@AuthenticationPrincipal User user, + @RequestBody @ApiValid Api request) { + MessageResponse response = shippingBusiness.shippingRequest(request.getBody(), + user.getUsername()); + return Api.OK(response); + } + + @GetMapping() //목록조회 + public Api getShippingList(@AuthenticationPrincipal User user) { + ShippingListResponse response = shippingBusiness.getShippingList(user.getUsername()); + return Api.OK(response); + } + + @GetMapping("/{shippingId}") //상세조회 + public Api getShippingDetail(@PathVariable Long shippingId) { + ShippingDetailResponse response = shippingBusiness.getShippingDetail(shippingId); + return Api.OK(response); + } + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/request/ShippingRequest.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/request/ShippingRequest.java new file mode 100644 index 00000000..92957511 --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/request/ShippingRequest.java @@ -0,0 +1,27 @@ +package warehouse.domain.shipping.controller.model.request; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import java.time.LocalDateTime; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ShippingRequest { + + private LocalDateTime deliveryDate; + + @NotBlank + @Size(max = 200) + private String deliveryAddress; + + @NotNull + @Size(min = 1) + private List goodsIdList; + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/MessageResponse.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/MessageResponse.java new file mode 100644 index 00000000..d0a6435e --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/MessageResponse.java @@ -0,0 +1,16 @@ +package warehouse.domain.shipping.controller.model.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MessageResponse { + + String message; + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingDetailResponse.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingDetailResponse.java new file mode 100644 index 00000000..ddfa5b5b --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingDetailResponse.java @@ -0,0 +1,19 @@ +package warehouse.domain.shipping.controller.model.response; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import warehouse.domain.goods.controller.model.GoodsResponse; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ShippingDetailResponse { + + private ShippingResponse shipping; + private List goods; + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingListResponse.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingListResponse.java new file mode 100644 index 00000000..cfad062c --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingListResponse.java @@ -0,0 +1,15 @@ +package warehouse.domain.shipping.controller.model.response; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ShippingListResponse { + List shipping; +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingResponse.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingResponse.java new file mode 100644 index 00000000..9ece259f --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingResponse.java @@ -0,0 +1,26 @@ +package warehouse.domain.shipping.controller.model.response; + +import db.domain.shipping.enums.ShippingStatus; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ShippingResponse { + + private Long shippingId; + + private LocalDateTime deliveryDate; + + private String deliveryAddress; + + private ShippingStatus status; + + private Long deliveryMan; + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java b/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java new file mode 100644 index 00000000..17ad0f8a --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java @@ -0,0 +1,58 @@ +package warehouse.domain.shipping.converter; + +import db.domain.shipping.ShippingEntity; +import global.annotation.Converter; +import java.util.List; +import java.util.stream.Collectors; +import warehouse.domain.goods.controller.model.GoodsResponse; +import warehouse.domain.shipping.controller.model.request.ShippingRequest; +import warehouse.domain.shipping.controller.model.response.MessageResponse; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; +import warehouse.domain.shipping.controller.model.response.ShippingListResponse; +import warehouse.domain.shipping.controller.model.response.ShippingResponse; + +@Converter +public class ShippingConverter { + + public ShippingEntity toEntity(ShippingRequest request) { + return ShippingEntity.builder() + .deliveryDate(request.getDeliveryDate()) + .deliveryAddress(request.getDeliveryAddress()) + .build(); + } + + public MessageResponse toMessageResponse(String message) { + return MessageResponse.builder() + .message(message) + .build(); + } + + public ShippingListResponse toResponseList(List entityList) { + + List shippingResponses = entityList.stream() + .map(entity -> this.toResponse(entity)).collect(Collectors.toList()); + + return ShippingListResponse.builder() + .shipping(shippingResponses) + .build(); + } + + public ShippingResponse toResponse(ShippingEntity entity) { + return ShippingResponse.builder() + .shippingId(entity.getId()) + .deliveryDate(entity.getDeliveryDate()) + .deliveryAddress(entity.getDeliveryAddress()) + .status(entity.getStatus()) + .deliveryMan(entity.getDeliveryMan()) + .build(); + } + + public ShippingDetailResponse toResponse(ShippingResponse shippingResponse, + List goodsResponses) { + return ShippingDetailResponse.builder() + .shipping(shippingResponse) + .goods(goodsResponses) + .build(); + } + +} diff --git a/warehouse/src/main/java/warehouse/domain/shipping/service/ShippingService.java b/warehouse/src/main/java/warehouse/domain/shipping/service/ShippingService.java new file mode 100644 index 00000000..558479a2 --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/shipping/service/ShippingService.java @@ -0,0 +1,33 @@ +package warehouse.domain.shipping.service; + +import db.domain.shipping.ShippingEntity; +import db.domain.shipping.ShippingRepository; +import db.domain.shipping.enums.ShippingStatus; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import warehouse.common.error.ShippingErrorCode; +import warehouse.common.exception.shipping.ShippingNotFoundException; + +@Service +@RequiredArgsConstructor +public class ShippingService { + + private final ShippingRepository shippingRepository; + + public ShippingEntity shippingRequest(ShippingEntity shippingEntity, Long userId) { + shippingEntity.setUserId(userId); + shippingEntity.setStatus(ShippingStatus.PENDING); // PENDING(출고 대기) 으로 변경 + return shippingRepository.save(shippingEntity); + } + + public List getShippingList(Long userId) { + return shippingRepository.findAllByUserIdOrderByIdDesc(userId); + } + + public ShippingEntity getShippingDetail(Long shippingId) { + return shippingRepository.findFirstById(shippingId).orElseThrow( + () -> new ShippingNotFoundException(ShippingErrorCode.SHIPPING_REQUEST_NOT_FOUND)); + } + +}