Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung committed Jul 22, 2024
2 parents c5ad5f1 + 60b1692 commit 0546d5c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<GoodsResponse>> getGoodsList(Long requestId) {

List<GoodsEntity> goodsList = goodsService.findAllByReceivingIdWithThrow(requestId);

List<List<GoodsResponse>> goodsResponse = new ArrayList<>();

goodsList.forEach(goodsEntity -> {

log.info("goodsId = {}", goodsEntity.getId());

List<ImageEntity> imageList = imageService.getImagesByGoodsId(goodsEntity.getId());

imageList.forEach(it -> log.info("imageList = {}", it.getId()));

List<ImageEntity> basicList = imageService.getImageUrlListBy(goodsEntity.getId(),
ImageKind.BASIC);
List<ImageEntity> faultList = imageService.getImageUrlListBy(goodsEntity.getId(),
ImageKind.FAULT);

ImageListResponse imageListResponse = imageConverter.toImageListResponse(basicList,
faultList);

goodsResponse.add(goodsConverter.toResponseListBy(goodsList, imageListResponse));

});

return goodsResponse;
}
}
Original file line number Diff line number Diff line change
@@ -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<List<List<GoodsResponse>>> receiving(@PathVariable Long requestId) {
List<List<GoodsResponse>> response = goodsBusiness.getGoodsList(requestId);
return Api.OK(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Expand Down Expand Up @@ -148,4 +150,8 @@ private void setGoodsId(List<GoodsRequest> goodsRequests, Long goodsId) {
updateImageDB(imageEntity);
}));
}

public List<ImageEntity> getImagesByGoodsId(Long goodsId) {
return imageRepository.findAllByGoodsIdOrderByIdDesc(goodsId);
}
}

0 comments on commit 0546d5c

Please sign in to comment.