diff --git a/src/main/java/com/backend/soullive_a/controller/ModelFitnessController.java b/src/main/java/com/backend/soullive_a/controller/ModelFitnessController.java new file mode 100644 index 0000000..f5810c8 --- /dev/null +++ b/src/main/java/com/backend/soullive_a/controller/ModelFitnessController.java @@ -0,0 +1,32 @@ +package com.backend.soullive_a.controller; + +import com.backend.soullive_a.dto.request.ModelFitnessRequest; +import com.backend.soullive_a.dto.response.model.fitness.ModelFitnessResponse; +import com.backend.soullive_a.exception.base.BaseResponse; +import com.backend.soullive_a.service.impl.ModelFitnessServiceImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/model/fitness") +public class ModelFitnessController { + private final ModelFitnessServiceImpl modelFitnessService; + + @GetMapping("") + public BaseResponse getModelFitness( + @RequestParam String modelName, + @RequestParam Long productId + ) { + return BaseResponse.builder() + .code(200) + .message("모델 적합도 조회에 성공했습니다.") + .isSuccess(true) + .data(modelFitnessService.getModelFitness(new ModelFitnessRequest(modelName, productId))) + .build(); + } + +} 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 17045ea..7f9ce85 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 @@ -36,16 +36,19 @@ public class ModelFitnessServiceImpl implements ModelFitnessService { @Override public ModelFitnessResponse getModelFitness(ModelFitnessRequest request) { Model model = modelRepository.findByModelName(request.modelName()) - .orElseThrow(() -> new NotFoundUserException()); + .orElseThrow(() -> new NotFoundUserException("해당 Model을 찾을 수 없습니다")); Product product = productRepository.findById(request.productId()) - .orElseThrow(() -> new NotFoundUserException()); //커스텀에러 + .orElseThrow(() -> new NotFoundUserException("해당 Product를 찾을 수 없습니다")); //커스텀에러 ProductModel productModel = productModelRepository.findByProductAndModel(product, model) - .orElseThrow(() -> new NotFoundUserException()); //커스텀에러 + .orElseThrow(() -> new NotFoundUserException( + String.format("product : %d, model : %s의 상품모델을 찾을 수 없습니다", product.getId(), model.getModelName()) + ) + ); //커스텀에러 ModelFitness modelFitness = modelFitnessRepository.findById(productModel.getId()) - .orElseThrow(() -> new NotFoundUserException()); //커스텀에러 + .orElseThrow(() -> new NotFoundUserException("모델적합도를 찾을수없습니다")); //커스텀에러 List modelImageKeywords = modelImageKeywordRepository.findAllByModel(model); List modelImageKeywordResponses = modelImageKeywords.stream() @@ -65,8 +68,9 @@ public ModelFitnessResponse getModelFitness(ModelFitnessRequest request) { return ModelFitnessResponse.builder() .scoreUrl(modelFitness.getScoreUrl()) .aiComment(modelFitness.getAiComment()) - .modelImageKeywordList(brandImageResponses) - .brandImageKeywordList(productImageResponses) + .modelImageKeywordList(modelImageKeywordResponses) + .brandImageKeywordList(brandImageResponses) + .productImageKeywordList(productImageResponses) .build(); } } diff --git a/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java b/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java index 2de4b59..6dc318e 100644 --- a/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java +++ b/src/main/java/com/backend/soullive_a/service/impl/ModelServiceImpl.java @@ -6,10 +6,12 @@ import com.backend.soullive_a.entity.Product; import com.backend.soullive_a.entity.model.Model; import com.backend.soullive_a.entity.model.ProductModel; +import com.backend.soullive_a.entity.model.fitness.ModelFitness; import com.backend.soullive_a.exception.custom.NotFoundUserException; import com.backend.soullive_a.repository.ModelRepository; import com.backend.soullive_a.repository.ProductModelRepository; import com.backend.soullive_a.repository.ProductRepository; +import com.backend.soullive_a.repository.model.fitness.ModelFitnessRepository; import com.backend.soullive_a.service.ModelService; import java.time.LocalDateTime; import java.util.List; @@ -24,14 +26,15 @@ public class ModelServiceImpl implements ModelService { private final ModelRepository modelRepository; private final ProductRepository productRepository; private final ProductModelRepository productModelRepository; + private final ModelFitnessRepository modelFitnessRepository; @Override @Transactional public ModelResponse getModel(String modelName,Long productId) { System.out.println(modelName); Model model = modelRepository.findByModelName(modelName) - .orElseThrow(() -> new NotFoundUserException()); - + .orElseThrow(() -> new NotFoundUserException("실페ㅐ")); + System.out.println(model.getModelName()+productId); //최근 조회 모델 데이터 업데이트 updateRecentViewModel(model,productId); @@ -50,6 +53,18 @@ public ModelResponse getModel(String modelName,Long productId) { .build(); } + private void createModelFitness( ProductModel productModel) { + + modelFitnessRepository.save( + ModelFitness.builder() + .productModel(productModel) + .aiComment("ai comment입니다") + .scoreUrl("점수 url입니다") + .build() + ); + + + } /** @@ -77,12 +92,15 @@ private void updateRecentViewModel(Model model, Long productId){ Product product = productRepository.findById(productId) .orElseThrow(NotFoundUserException::new); - productModelRepository.save( - ProductModel.builder() - .model(model) - .product(product) - .searchTime(LocalDateTime.now()) - .build() + ProductModel productModel = productModelRepository.save( + ProductModel.builder() + .model(model) + .product(product) + .searchTime(LocalDateTime.now()) + .build() ); + + //모델 적합도 더미데이터 생성 + createModelFitness(productModel); } } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 0ff2c7c..0a06c22 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -150,3 +150,7 @@ VALUES (6, 3, '톱스타뉴스', '2023-08-19', '"수지도 5만 원인데”...배우 김고은, 
팬미팅 가격 고가 논란', 'https://www.topstarnews.net/news/articleView.html?idxno=773836'), (7, 3, '국제신문', '2019-05-05', '김고은 측 ''인터뷰 논란 악플 경고글'' 돌연 삭제...
이유는?', 'https://sports.donga.com/article/all/20200429/100861465/2'); +-- 모델 적합도 +-- INSERT INTO test_jinwoo.model_fitness (model_fitenss_id, product_model_id, ai_comment, score_url) +-- VALUES +-- (1, 1, '김희애의 우아하고 고급스러운 이미지와 함께 가족적인 이미지가 어우러져 lg 시그니처 브랜드의 프리미엄적인 이미지와 고품질 제품에 잘 어울릴 것이라고 판단 됩니다.', 'image.png'); \ No newline at end of file