Skip to content

Commit

Permalink
Merge pull request #43 from FX-BAOBAB/refactor/shippinglist
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung authored Aug 2, 2024
2 parents 687f81c + f931c1b commit c72df36
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
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;
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;
Expand Down Expand Up @@ -49,14 +49,23 @@ public MessageResponse shippingRequest(ShippingRequest request, String email) {

public ShippingListResponse getShippingList(String email) {
Long userId = getUserWithThrow(email).getId();

List<ShippingEntity> shippingEntityList = shippingService.getShippingList(userId);

List<ShippingDetailResponse> shippingDetailResponseList = shippingEntityList.stream().map(shippingEntity -> {
return getShippingDetail(shippingEntity.getId());
List<ShippingDetailResponse> shippingResponse = shippingEntityList.stream().map(shippingEntity -> {
List<GoodsEntity> goodsEntityList = goodsService.findAllByShippingIdWithThrow(
shippingEntity.getId());

List<GoodsResponse> goodsResponseList = goodsEntityList.stream()
.map(goodsEntity -> {
ImageListResponse imageListResponse = imageConverter.toImageListResponse(
goodsEntity);
return goodsConverter.toResponse(goodsEntity, imageListResponse);
}).toList();

return shippingConverter.toResponse(shippingEntity, goodsResponseList);
}).toList();

return shippingConverter.toResponseList(shippingDetailResponseList);
return shippingConverter.toResponse(shippingResponse);
}

public ShippingDetailResponse getShippingDetail(Long shippingId) {
Expand All @@ -71,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,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
Expand All @@ -38,7 +38,8 @@ public Api<MessageResponse> shippingRequest(@AuthenticationPrincipal User user,
@GetMapping() //목록조회
@Operation(summary = "[출고 요청서 목록 보기]")
public Api<ShippingListResponse> getShippingList(@AuthenticationPrincipal User user) {
ShippingListResponse response = shippingBusiness.getShippingList(user.getUsername());
ShippingListResponse response = shippingBusiness.getShippingList(
user.getUsername());
return Api.OK(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +15,15 @@
@Builder
public class ShippingDetailResponse {

private ShippingResponse shipping;
private List<GoodsResponse> goods;
private Long shippingId;

private LocalDateTime deliveryDate;

private String deliveryAddress;

private ShippingStatus status;

private Long deliveryMan;

private List<GoodsResponse> goods;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
@AllArgsConstructor
@Builder
public class ShippingListResponse {
List<ShippingDetailResponse> shipping;

private List<ShippingDetailResponse> shippingList;

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,26 +29,19 @@ public MessageResponse toMessageResponse(String message) {
.build();
}

public ShippingListResponse toResponseList(List<ShippingDetailResponse> shippingDetailResponseList) {
public ShippingListResponse toResponse(List<ShippingDetailResponse> shippingResponses) {
return ShippingListResponse.builder()
.shipping(shippingDetailResponseList)
.shippingList(shippingResponses)
.build();
}

public ShippingResponse toResponse(ShippingEntity entity) {
return ShippingResponse.builder()
public ShippingDetailResponse toResponse(ShippingEntity entity, List<GoodsResponse> 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<GoodsResponse> goodsResponses) {
return ShippingDetailResponse.builder()
.shipping(shippingResponse)
.goods(goodsResponses)
.build();
}
Expand Down

0 comments on commit c72df36

Please sign in to comment.