-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 모델 적합도 조회 api 및 스웨거 설명 추가
- Loading branch information
Showing
12 changed files
with
244 additions
and
36 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/com/backend/soullive_a/controller/ModelFitnessController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/backend/soullive_a/dto/request/ModelFitnessRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/com/backend/soullive_a/dto/response/ModelImageKeywordResponse.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/backend/soullive_a/dto/response/model/fitness/ModelFitnessResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
) { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/backend/soullive_a/entity/model/fitness/ModelFitness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/soullive_a/repository/model/fitness/ModelFitnessRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/backend/soullive_a/service/ModelFitnessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/backend/soullive_a/service/impl/ModelFitnessServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.