From f2f3477a62ea81f1f316f48d194132ac15cf4df7 Mon Sep 17 00:00:00 2001 From: SEOB Date: Thu, 1 Aug 2024 14:41:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?SB-235=20(refactor)=20:=20=EC=B6=9C?= =?UTF-8?q?=EA=B3=A0=20=EC=9A=94=EC=B2=AD=EC=84=9C=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SB-235 (refactor) : 출고 요청서 목록 조회 응답 형식 변경 1. ShippingBusiness - List 를 반환하도록 변경 2. ShippingListResponse 3. ShippingApiController 4. ShippingConverter --- .../shipping/business/ShippingBusiness.java | 21 +++++++++++++------ .../controller/ShippingApiController.java | 6 ++++-- .../model/response/ShippingListResponse.java | 17 ++++++++++++++- .../shipping/converter/ShippingConverter.java | 9 ++++++-- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java index 562efde6..78454a62 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java @@ -13,6 +13,7 @@ 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.MessageResponse; import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; @@ -33,6 +34,7 @@ public class ShippingBusiness { private final ShippingConverter shippingConverter; private final ImageConverter imageConverter; private final GoodsConverter goodsConverter; + private final ImageService imageService; @Transactional public MessageResponse shippingRequest(ShippingRequest request, String email) { @@ -47,16 +49,23 @@ public MessageResponse shippingRequest(ShippingRequest request, String email) { return shippingConverter.toMessageResponse("출고 신청이 완료되었습니다."); } - public ShippingListResponse getShippingList(String email) { + public List getShippingList(String email) { Long userId = getUserWithThrow(email).getId(); - List shippingEntityList = shippingService.getShippingList(userId); - List shippingDetailResponseList = shippingEntityList.stream().map(shippingEntity -> { - return getShippingDetail(shippingEntity.getId()); - }).toList(); + return shippingEntityList.stream().map(shippingEntity -> { + List goodsEntityList = goodsService.findAllByShippingIdWithThrow( + shippingEntity.getId()); - return shippingConverter.toResponseList(shippingDetailResponseList); + List goodsResponseList = goodsEntityList.stream() + .map(goodsEntity -> { + ImageListResponse imageListResponse = imageConverter.toImageListResponse( + goodsEntity); + return goodsConverter.toResponse(goodsEntity, imageListResponse); + }).toList(); + + return shippingConverter.toResponse(shippingEntity, goodsResponseList); + }).toList(); } public ShippingDetailResponse getShippingDetail(Long shippingId) { diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java index 167f1c0e..9597e2c4 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java @@ -3,6 +3,7 @@ import global.annotation.ApiValid; import global.api.Api; import io.swagger.v3.oas.annotations.Operation; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.User; @@ -37,8 +38,9 @@ public Api shippingRequest(@AuthenticationPrincipal User user, @GetMapping() //목록조회 @Operation(summary = "[출고 요청서 목록 보기]") - public Api getShippingList(@AuthenticationPrincipal User user) { - ShippingListResponse response = shippingBusiness.getShippingList(user.getUsername()); + public Api> getShippingList(@AuthenticationPrincipal User user) { + List response = shippingBusiness.getShippingList( + user.getUsername()); return Api.OK(response); } 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 index 0acb6ad8..20014288 100644 --- 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 @@ -1,15 +1,30 @@ package warehouse.domain.shipping.controller.model.response; +import db.domain.shipping.enums.ShippingStatus; +import java.time.LocalDateTime; 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 ShippingListResponse { - List shipping; + + private Long shippingId; + + private LocalDateTime deliveryDate; + + private String deliveryAddress; + + private ShippingStatus status; + + private Long deliveryMan; + + private List goods; } + diff --git a/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java b/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java index 0eaf94e2..ce89ed98 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java @@ -31,9 +31,14 @@ public MessageResponse toMessageResponse(String message) { .build(); } - public ShippingListResponse toResponseList(List shippingDetailResponseList) { + public ShippingListResponse toResponse(ShippingEntity entity, List goodsResponses) { return ShippingListResponse.builder() - .shipping(shippingDetailResponseList) + .shippingId(entity.getId()) + .deliveryDate(entity.getDeliveryDate()) + .deliveryAddress(entity.getDeliveryAddress()) + .status(entity.getStatus()) + .deliveryMan(entity.getDeliveryMan()) + .goods(goodsResponses) .build(); } From f931c1b423b61b9edabcaa357074017eb2947f62 Mon Sep 17 00:00:00 2001 From: SEOB Date: Fri, 2 Aug 2024 10:07:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?SB-235=20(refactor)=20:=20=EC=B6=9C?= =?UTF-8?q?=EA=B3=A0=20=EC=9A=94=EC=B2=AD=EC=84=9C=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?&=20=EC=83=81=EC=84=B8=20=EB=B3=B4=EA=B8=B0=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SB-235 (refactor) : 출고 요청서 목록 & 상세 보기 응답 형식 변경 1. ShippinResponse 제거 -> ShippingDetailResponse 로 대체 2. ShippingListResponse - List 로 변경 3. ShippingApiController - 요청서 목록 조회 반환 형식 변경 4. ShippingConverter - 사용하지 않는 `toResponse` 메서드 제거 5. ShippingBusiness - 목록 보기 & 상세 보기 로직 및 반환값 변경 --- .../shipping/business/ShippingBusiness.java | 14 +++++----- .../controller/ShippingApiController.java | 7 +++-- .../response/ShippingDetailResponse.java | 14 ++++++++-- .../model/response/ShippingListResponse.java | 14 +--------- .../model/response/ShippingResponse.java | 26 ------------------- .../shipping/converter/ShippingConverter.java | 24 ++++------------- 6 files changed, 27 insertions(+), 72 deletions(-) delete mode 100644 warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingResponse.java diff --git a/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java index 78454a62..048f7705 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/business/ShippingBusiness.java @@ -16,9 +16,8 @@ import warehouse.domain.image.service.ImageService; 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; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; import warehouse.domain.shipping.controller.model.response.ShippingStatusResponse; import warehouse.domain.shipping.converter.ShippingConverter; import warehouse.domain.shipping.service.ShippingService; @@ -34,7 +33,6 @@ public class ShippingBusiness { private final ShippingConverter shippingConverter; private final ImageConverter imageConverter; private final GoodsConverter goodsConverter; - private final ImageService imageService; @Transactional public MessageResponse shippingRequest(ShippingRequest request, String email) { @@ -49,11 +47,11 @@ public MessageResponse shippingRequest(ShippingRequest request, String email) { return shippingConverter.toMessageResponse("출고 신청이 완료되었습니다."); } - public List getShippingList(String email) { + public ShippingListResponse getShippingList(String email) { Long userId = getUserWithThrow(email).getId(); List shippingEntityList = shippingService.getShippingList(userId); - return shippingEntityList.stream().map(shippingEntity -> { + List shippingResponse = shippingEntityList.stream().map(shippingEntity -> { List goodsEntityList = goodsService.findAllByShippingIdWithThrow( shippingEntity.getId()); @@ -66,6 +64,8 @@ public List getShippingList(String email) { return shippingConverter.toResponse(shippingEntity, goodsResponseList); }).toList(); + + return shippingConverter.toResponse(shippingResponse); } public ShippingDetailResponse getShippingDetail(Long shippingId) { @@ -80,9 +80,7 @@ public ShippingDetailResponse getShippingDetail(Long shippingId) { return goodsConverter.toResponse(goodsEntity, imageListResponse); }).toList(); - ShippingResponse shippingResponse = shippingConverter.toResponse(shippingEntity); - - return shippingConverter.toResponse(shippingResponse, goodsResponseList); + return shippingConverter.toResponse(shippingEntity, goodsResponseList); } public ShippingStatusResponse getCurrentStatusBy(Long shippingId) { diff --git a/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java index 9597e2c4..beabf5d6 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/controller/ShippingApiController.java @@ -3,7 +3,6 @@ import global.annotation.ApiValid; import global.api.Api; import io.swagger.v3.oas.annotations.Operation; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.User; @@ -15,9 +14,9 @@ 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; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; import warehouse.domain.shipping.controller.model.response.ShippingStatusResponse; @RestController @@ -38,8 +37,8 @@ public Api shippingRequest(@AuthenticationPrincipal User user, @GetMapping() //목록조회 @Operation(summary = "[출고 요청서 목록 보기]") - public Api> getShippingList(@AuthenticationPrincipal User user) { - List response = shippingBusiness.getShippingList( + public Api getShippingList(@AuthenticationPrincipal User user) { + ShippingListResponse response = shippingBusiness.getShippingList( user.getUsername()); return Api.OK(response); } 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 index ddfa5b5b..b428bda0 100644 --- 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 @@ -1,5 +1,7 @@ package warehouse.domain.shipping.controller.model.response; +import db.domain.shipping.enums.ShippingStatus; +import java.time.LocalDateTime; import java.util.List; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,7 +15,15 @@ @Builder public class ShippingDetailResponse { - private ShippingResponse shipping; - private List goods; + private Long shippingId; + + private LocalDateTime deliveryDate; + + private String deliveryAddress; + private ShippingStatus status; + + private Long deliveryMan; + + 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 index 20014288..451241e1 100644 --- 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 @@ -1,13 +1,10 @@ package warehouse.domain.shipping.controller.model.response; -import db.domain.shipping.enums.ShippingStatus; -import java.time.LocalDateTime; 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 @@ -15,16 +12,7 @@ @Builder public class ShippingListResponse { - private Long shippingId; + private List shippingList; - private LocalDateTime deliveryDate; - - private String deliveryAddress; - - private ShippingStatus status; - - private Long deliveryMan; - - private List goods; } 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 deleted file mode 100644 index 9ece259f..00000000 --- a/warehouse/src/main/java/warehouse/domain/shipping/controller/model/response/ShippingResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -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 index ce89ed98..a9143dc4 100644 --- a/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java +++ b/warehouse/src/main/java/warehouse/domain/shipping/converter/ShippingConverter.java @@ -5,13 +5,11 @@ import global.annotation.Converter; import java.util.Arrays; 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; +import warehouse.domain.shipping.controller.model.response.ShippingDetailResponse; import warehouse.domain.shipping.controller.model.response.ShippingStatusResponse; @Converter @@ -31,31 +29,19 @@ public MessageResponse toMessageResponse(String message) { .build(); } - public ShippingListResponse toResponse(ShippingEntity entity, List goodsResponses) { + public ShippingListResponse toResponse(List shippingResponses) { return ShippingListResponse.builder() - .shippingId(entity.getId()) - .deliveryDate(entity.getDeliveryDate()) - .deliveryAddress(entity.getDeliveryAddress()) - .status(entity.getStatus()) - .deliveryMan(entity.getDeliveryMan()) - .goods(goodsResponses) + .shippingList(shippingResponses) .build(); } - public ShippingResponse toResponse(ShippingEntity entity) { - return ShippingResponse.builder() + public ShippingDetailResponse toResponse(ShippingEntity entity, List goodsResponses) { + return ShippingDetailResponse.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(); }