Skip to content

Commit

Permalink
Merge pull request #35 from soulive-A/feat/#34-ModelFitness
Browse files Browse the repository at this point in the history
[feat] 모델 적합도 조회 api 및 스웨거 설명 추가
  • Loading branch information
lsm-del authored Mar 8, 2024
2 parents f589ccf + 4ac2956 commit 03c57e5
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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;

@Tag(name = "모델 적합도 API", description = "모델 적합도 이슈 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/model/fitness")
public class ModelFitnessController {
private final ModelFitnessServiceImpl modelFitnessService;

@Operation(summary = "모델 적합도 API", description = "모델 적합도 조회 API입니다.")
@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 @@ -3,17 +3,22 @@
import com.backend.soullive_a.dto.response.model.issue.ModelIssueResponse;
import com.backend.soullive_a.exception.base.BaseResponse;
import com.backend.soullive_a.service.ModelIssueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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;

@Tag(name = "모델 부정 이슈 API", description = "모델 부정 이슈 API입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("api/model/issue")
public class ModelIssueController {
private final ModelIssueService modelIssueService;

@Operation(summary = "모델 부정 이슈 조회 API", description = "특정 모델 부정 이슈 조회 API입니다.")
@GetMapping()
public BaseResponse<ModelIssueResponse> getIssue(@RequestParam String modelName) {
return BaseResponse.<ModelIssueResponse>builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.backend.soullive_a.dto.request;

public record ModelFitnessRequest(
String modelName,
Long productId
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.backend.soullive_a.dto.response.model.fitness;

import jakarta.persistence.Column;
import lombok.Builder;

import java.util.List;

@Builder

public record ModelFitnessResponse(
String scoreUrl,
String aiComment,
List<String> modelImageKeywordList,
List<String> brandImageKeywordList,
List<String> productImageKeywordList


) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.backend.soullive_a.entity.model.fitness;

import com.backend.soullive_a.entity.model.ProductModel;
import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ModelFitness {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MODEL_FITENSS_ID", nullable = false)
private Long id;

@Column(name = "SCORE_URL", nullable = false)
private String scoreUrl;

@Column(name = "AI_COMMENT", nullable = false)
private String aiComment;

@OneToOne
@JoinColumn(name = "PRODUCT_MODEL_ID")
private ProductModel productModel;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.backend.soullive_a.repository;

import com.backend.soullive_a.dto.response.RecentModelResponse;
import com.backend.soullive_a.entity.Product;
import com.backend.soullive_a.entity.model.Model;
import com.backend.soullive_a.entity.model.ProductModel;
import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.parameters.P;

public interface ProductModelRepository extends JpaRepository<ProductModel, Long> {

Expand All @@ -16,4 +21,6 @@ public interface ProductModelRepository extends JpaRepository<ProductModel, Long
+ "Where p.product.id = :productId "
+ "ORDER BY p.searchTime DESC")
List<RecentModelResponse> getRecentModels(@Param("productId") Long productId);

Optional<ProductModel> findByProductAndModel(Product product, Model model);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.backend.soullive_a.repository.model.fitness;

import com.backend.soullive_a.entity.model.fitness.ModelFitness;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ModelFitnessRepository extends JpaRepository<ModelFitness, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.backend.soullive_a.service;

import com.backend.soullive_a.dto.request.ModelFitnessRequest;
import com.backend.soullive_a.dto.response.model.fitness.ModelFitnessResponse;

public interface ModelFitnessService {
public ModelFitnessResponse getModelFitness(ModelFitnessRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.backend.soullive_a.service.impl;

import com.backend.soullive_a.dto.request.ModelFitnessRequest;
import com.backend.soullive_a.dto.response.model.fitness.ModelFitnessResponse;
import com.backend.soullive_a.entity.BrandImage;
import com.backend.soullive_a.entity.Product;
import com.backend.soullive_a.entity.ProductImage;
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.entity.model.introduction.ModelImageKeyword;
import com.backend.soullive_a.exception.custom.NotFoundUserException;
import com.backend.soullive_a.repository.*;
import com.backend.soullive_a.repository.model.fitness.ModelFitnessRepository;
import com.backend.soullive_a.repository.model.introduction.ModelImageKeywordRepository;
import com.backend.soullive_a.service.ModelFitnessService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class ModelFitnessServiceImpl implements ModelFitnessService {

private final ModelFitnessRepository modelFitnessRepository;
private final ModelRepository modelRepository;
private final ProductRepository productRepository;
private final ProductModelRepository productModelRepository;
private final ModelImageKeywordRepository modelImageKeywordRepository;
private final BrandImageRepository brandImageRepository;
private final ProductImageRepository productImageRepository;

@Override
public ModelFitnessResponse getModelFitness(ModelFitnessRequest request) {
Model model = modelRepository.findByModelName(request.modelName())
.orElseThrow(() -> new NotFoundUserException("해당 Model을 찾을 수 없습니다"));

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())
)
); //커스텀에러

ModelFitness modelFitness = modelFitnessRepository.findById(productModel.getId())
.orElseThrow(() -> new NotFoundUserException("모델적합도를 찾을수없습니다")); //커스텀에러

List<ModelImageKeyword> modelImageKeywords = modelImageKeywordRepository.findAllByModel(model);
List<String> modelImageKeywordResponses = modelImageKeywords.stream()
.map(ModelImageKeyword::getKeyword)
.collect(Collectors.toList());

List<BrandImage> brandImages = brandImageRepository.findAllByProductId(product.getId());
List<String> brandImageResponses = brandImages.stream()
.map(BrandImage::getBrandImage)
.collect(Collectors.toList());

List<ProductImage> productImages = productImageRepository.findAllByProductId(product.getId());
List<String> productImageResponses = productImages.stream()
.map(ProductImage::getProductImage)
.collect(Collectors.toList());

return ModelFitnessResponse.builder()
.scoreUrl(modelFitness.getScoreUrl())
.aiComment(modelFitness.getAiComment())
.modelImageKeywordList(modelImageKeywordResponses)
.brandImageKeywordList(brandImageResponses)
.productImageKeywordList(productImageResponses)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,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.ArrayList;
Expand All @@ -26,14 +28,13 @@ 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());

//최근 조회 모델 데이터 업데이트
updateRecentViewModel(model,productId);

Expand All @@ -52,6 +53,33 @@ public ModelResponse getModel(String modelName,Long productId) {
.build();
}

private void createModelFitness( ProductModel productModel) {
String aiComment="ai 한줄 평 준비 중 입니다.";
String scoreUrl="https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/heeae_modelFitness_score.png";

if (productModel.getModel().getId() == 1) {
aiComment = "김희애의 우아하고 고급스러운 이미지와 함께 가족적인 이미지가 어우러져 lg 시그니처 브랜드의 프리미엄적인 이미지와 고품질 제품에 잘 어울릴 것이라고 판단 됩니다.";
scoreUrl="https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/heeae_modelFitness_score.png";
}
else if (productModel.getModel().getId() == 2) {
aiComment = "한지민은 깨끗하고 바른 이미지로 LG시그니처와 어울리지만 현재 목표하는 프리미엄 이미지를 강조하기에는 다소 아쉬운 모델입니다.";
scoreUrl="https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/hanjimin_modelFitness_score.png";
} else if (productModel.getModel().getId() == 3) {
aiComment = "김고은은 세련되고 사랑스러운 이미지로 LG 시그니처가 목표로 하는 세련되고 대중에게 친숙한 이미지와 적합합니다.";
scoreUrl="https://soullive-bucket.s3.ap-northeast-2.amazonaws.com/goeun_modelFitness_score.png";
}


modelFitnessRepository.save(
ModelFitness.builder()
.productModel(productModel)
.aiComment(aiComment)
.scoreUrl(scoreUrl)
.build()
);


}


/**
Expand Down Expand Up @@ -91,12 +119,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);
}
}
Loading

0 comments on commit 03c57e5

Please sign in to comment.