Skip to content

Commit

Permalink
feat : #34 모델조회시 마다 모델적합도 데이터 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
j2noo committed Mar 8, 2024
1 parent 07e0890 commit e93ae5a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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<ModelFitnessResponse> getModelFitness(
@RequestParam String modelName,
@RequestParam Long productId
) {
return BaseResponse.<ModelFitnessResponse>builder()
.code(200)
.message("모델 적합도 조회에 성공했습니다.")
.isSuccess(true)
.data(modelFitnessService.getModelFitness(new ModelFitnessRequest(modelName, productId)))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelImageKeyword> modelImageKeywords = modelImageKeywordRepository.findAllByModel(model);
List<String> modelImageKeywordResponses = modelImageKeywords.stream()
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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()
);


}


/**
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit e93ae5a

Please sign in to comment.