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 d2acc105..c8f7b52e 100644 --- a/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java +++ b/warehouse/src/main/java/warehouse/domain/goods/business/GoodsBusiness.java @@ -1,15 +1,57 @@ package warehouse.domain.goods.business; +import db.domain.goods.GoodsEntity; +import db.domain.image.ImageEntity; +import db.domain.image.enums.ImageKind; import global.annotation.Business; +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +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.controller.model.ImageResponse; +import warehouse.domain.image.converter.ImageConverter; +import warehouse.domain.image.service.ImageService; +@Slf4j @Business @RequiredArgsConstructor public class GoodsBusiness { private final GoodsConverter goodsConverter; private final GoodsService goodsService; + private final ImageService imageService; + private final ImageConverter imageConverter; + public List> getGoodsList(Long requestId) { + + List goodsList = goodsService.findAllByReceivingIdWithThrow(requestId); + + List> goodsResponse = new ArrayList<>(); + + goodsList.forEach(goodsEntity -> { + + log.info("goodsId = {}", goodsEntity.getId()); + + List imageList = imageService.getImagesByGoodsId(goodsEntity.getId()); + + imageList.forEach(it -> log.info("imageList = {}", it.getId())); + + List basicList = imageService.getImageUrlListBy(goodsEntity.getId(), + ImageKind.BASIC); + List faultList = imageService.getImageUrlListBy(goodsEntity.getId(), + ImageKind.FAULT); + + ImageListResponse imageListResponse = imageConverter.toImageListResponse(basicList, + faultList); + + goodsResponse.add(goodsConverter.toResponseListBy(goodsList, imageListResponse)); + + }); + + return goodsResponse; + } } diff --git a/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java b/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java new file mode 100644 index 00000000..0e074a82 --- /dev/null +++ b/warehouse/src/main/java/warehouse/domain/goods/controller/GoodsController.java @@ -0,0 +1,26 @@ +package warehouse.domain.goods.controller; + +import global.api.Api; +import java.util.List; +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; +import warehouse.domain.goods.business.GoodsBusiness; +import warehouse.domain.goods.controller.model.GoodsResponse; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/goods") +public class GoodsController { + + private final GoodsBusiness goodsBusiness; + + @GetMapping("/receiving/{requestId}") + public Api>> receiving(@PathVariable Long requestId) { + List> response = goodsBusiness.getGoodsList(requestId); + return Api.OK(response); + } + +} diff --git a/warehouse/src/main/java/warehouse/domain/image/service/ImageService.java b/warehouse/src/main/java/warehouse/domain/image/service/ImageService.java index a184d11c..e683478d 100644 --- a/warehouse/src/main/java/warehouse/domain/image/service/ImageService.java +++ b/warehouse/src/main/java/warehouse/domain/image/service/ImageService.java @@ -26,6 +26,7 @@ import warehouse.common.exception.image.ImageNotFoundException; import warehouse.common.exception.image.ImageStorageException; import warehouse.domain.goods.controller.model.GoodsRequest; +import warehouse.domain.goods.service.GoodsService; import warehouse.domain.image.common.ImageUtils; @Slf4j @@ -39,6 +40,7 @@ public class ImageService { private final ImageRepository imageRepository; private final Path fileStorageLocation; + private final GoodsService goodsService; public void uploadImage(MultipartFile file, ImageEntity entity) { @@ -148,4 +150,8 @@ private void setGoodsId(List goodsRequests, Long goodsId) { updateImageDB(imageEntity); })); } + + public List getImagesByGoodsId(Long goodsId) { + return imageRepository.findAllByGoodsIdOrderByIdDesc(goodsId); + } } \ No newline at end of file