From ccee0d68d1a02f0405c901a3a39230b2d1cad303 Mon Sep 17 00:00:00 2001 From: Jinwoo Park Date: Sat, 9 Mar 2024 10:04:38 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20#39=20=EB=AA=A8=EB=8D=B8=EC=A0=81?= =?UTF-8?q?=ED=95=A9=EB=8F=84=20=EB=8B=A4=EC=A4=91=EB=B0=98=ED=99=98=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soullive_a/repository/ProductModelRepository.java | 4 +++- .../soullive_a/service/impl/ModelFitnessServiceImpl.java | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/backend/soullive_a/repository/ProductModelRepository.java b/src/main/java/com/backend/soullive_a/repository/ProductModelRepository.java index 69d3828..689c304 100644 --- a/src/main/java/com/backend/soullive_a/repository/ProductModelRepository.java +++ b/src/main/java/com/backend/soullive_a/repository/ProductModelRepository.java @@ -22,5 +22,7 @@ public interface ProductModelRepository extends JpaRepository getRecentModels(@Param("productId") Long productId); - Optional findByProductAndModel(Product product, Model model); +// Optional findByProductAndModel(Product product, Model model); + ProductModel findTopByProductAndModelOrderByIdDesc(Product product, Model model); + } diff --git a/src/main/java/com/backend/soullive_a/service/impl/ModelFitnessServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ModelFitnessServiceImpl.java index 7f9ce85..f4b47f6 100644 --- a/src/main/java/com/backend/soullive_a/service/impl/ModelFitnessServiceImpl.java +++ b/src/main/java/com/backend/soullive_a/service/impl/ModelFitnessServiceImpl.java @@ -41,11 +41,8 @@ public ModelFitnessResponse getModelFitness(ModelFitnessRequest request) { Product product = productRepository.findById(request.productId()) .orElseThrow(() -> new NotFoundUserException("해당 Product를 찾을 수 없습니다")); //커스텀에러 - ProductModel productModel = productModelRepository.findByProductAndModel(product, model) - .orElseThrow(() -> new NotFoundUserException( - String.format("product : %d, model : %s의 상품모델을 찾을 수 없습니다", product.getId(), model.getModelName()) - ) - ); //커스텀에러 + ProductModel productModel = productModelRepository.findTopByProductAndModelOrderByIdDesc(product, model); + ModelFitness modelFitness = modelFitnessRepository.findById(productModel.getId()) .orElseThrow(() -> new NotFoundUserException("모델적합도를 찾을수없습니다")); //커스텀에러