Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public ApiResponse<LibraryCompareResponseDTO.CompareResult> compareLibrariesTest
.key("차량보유")
.values(List.of("있음"))
.build()))
.color("#4169E1")
.build();

// Group B 정보
Expand All @@ -240,7 +239,6 @@ public ApiResponse<LibraryCompareResponseDTO.CompareResult> compareLibrariesTest
.key("연령")
.values(List.of("30-39세"))
.build()))
.color("#FF69B4")
.build();

// 주요 특성 (특성 1, 2, 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public static class GroupInfo {

@JsonProperty("filters")
private List<Filter> filters;

@JsonProperty("color")
private String color;
}

@Getter
Expand Down

Large diffs are not rendered by default.

59 changes: 54 additions & 5 deletions src/main/java/DiffLens/back_end/global/fastapi/FastApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FastApiClient {

/**
*
* @param type fast api에 보낼 요청을 관리하는 enum - FastApiRequestType
* @param type fast api에 보낼 요청을 관리하는 enum - FastApiRequestType
* @param requestBody fast api에 요청 보낼 클래스의 타입
* @return fast api 로부터 응답받은 데이터 ( R )
* @param <T> request body의 클래스
Expand All @@ -35,14 +35,14 @@ public <T, R> R sendRequest(FastApiRequestType type, T requestBody) {
}

R block = null;
try{
try {
block = fastApiWebClient.post()
.uri(type.getUri())
.bodyValue(requestBody)
.retrieve()
.bodyToMono((Class<R>) type.getResponseType())
.block();
}catch (Exception e){ // fast api 호출 중 에러 발생시 예외 발생
} catch (Exception e) { // fast api 호출 중 에러 발생시 예외 발생
throw new ErrorHandler(ErrorStatus.SUB_SERVER_ERROR);
}

Expand All @@ -52,8 +52,8 @@ public <T, R> R sendRequest(FastApiRequestType type, T requestBody) {
/**
* PathVariable을 사용하는 GET 요청
*
* @param type fast api에 보낼 요청을 관리하는 enum - FastApiRequestType
* @param requestBody 요청 본문 (null 가능)
* @param type fast api에 보낼 요청을 관리하는 enum - FastApiRequestType
* @param requestBody 요청 본문 (null 가능)
* @param pathVariables URI에 포함될 경로 변수들
* @return fast api 로부터 응답받은 데이터 ( R )
* @param <T> request body의 클래스
Expand All @@ -75,4 +75,53 @@ public <T, R> R sendRequestWithPathVariable(FastApiRequestType type, T requestBo
return block;
}

/**
* Query Parameter를 사용하는 POST 요청
*
* @param type fast api에 보낼 요청을 관리하는 enum - FastApiRequestType
* @param queryParams 쿼리 파라미터 맵 (key-value 쌍)
* @return fast api 로부터 응답받은 데이터 ( R )
* @param <R> response body의 클래스
*/
@LogExecutionTime("서브서버 호출 소요시간")
public <R> R sendRequestWithQueryParams(FastApiRequestType type, java.util.Map<String, Object> queryParams) {
R block = null;
try {
block = fastApiWebClient.post()
.uri(uriBuilder -> {
var builder = uriBuilder.path(type.getUri());
queryParams.forEach((key, value) -> {
if (value != null) {
builder.queryParam(key, value);
}
});
return builder.build();
})
.retrieve()
.bodyToMono((Class<R>) type.getResponseType())
.block();
} catch (WebClientResponseException e) {
// 서브서버의 실제 응답 상태 코드와 메시지 로깅
System.err.println("=== 서브서버 응답 오류 ===");
System.err.println("URI: " + type.getUri());
System.err.println("Query Params: " + queryParams);
System.err.println("Status Code: " + e.getStatusCode());
System.err.println("Response Body: " + e.getResponseBodyAsString());
System.err.println("Error Message: " + e.getMessage());
e.printStackTrace();
throw new ErrorHandler(ErrorStatus.SUB_SERVER_ERROR);
} catch (Exception e) {
// 기타 예외 (네트워크 오류, 타임아웃 등)
System.err.println("=== 서브서버 요청 오류 ===");
System.err.println("URI: " + type.getUri());
System.err.println("Query Params: " + queryParams);
System.err.println("Error Type: " + e.getClass().getName());
System.err.println("Error Message: " + e.getMessage());
e.printStackTrace();
throw new ErrorHandler(ErrorStatus.SUB_SERVER_ERROR);
}

return block;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public enum FastApiRequestType {
RECOMMENDATIONS_BY_MEMBER("/api/quick-search/recommendations/by-member",
FastHomeRequestDTO.HomeRecommendByMemberRequest.class,
FastHomeResponseDTO.HomeRecommend.class),
COMPARE("/ai/compare", FastLibraryRequestDTO.LibraryCompare.class,

// 라이브러리 비교
COMPARE("/api/cohort-comparison/compare", Void.class,
FastLibraryCompareResponseDTO.CompareResult.class),

// 차트
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public FastNaturalLanguageResponseDTO.NaturalSearch getNaturalSearch(
}

// 자연어 검색2
public MainSearchResponse getMainSearch(MainSearchRequest request){
public MainSearchResponse getMainSearch(MainSearchRequest request) {
return fastApiClient.sendRequest(FastApiRequestType.NATURAL_SEARCH2, request);
}

// 라이브러리 비교
public FastLibraryCompareResponseDTO.CompareResult compareLibraries(FastLibraryRequestDTO.LibraryCompare request) {
return fastApiClient.sendRequest(FastApiRequestType.COMPARE, request);
public FastLibraryCompareResponseDTO.CompareResult compareLibraries(Long cohort1Id, Long cohort2Id) {
java.util.Map<String, Object> queryParams = new java.util.HashMap<>();
queryParams.put("cohort_1_id", cohort1Id);
queryParams.put("cohort_2_id", cohort2Id);
return fastApiClient.sendRequestWithQueryParams(FastApiRequestType.COMPARE, queryParams);
}

// 추천검색
Expand All @@ -47,8 +50,7 @@ public FastChartResponseDTO.ChartRecommendationsResponse getChartRecommendations
return fastApiClient.sendRequestWithPathVariable(
FastApiRequestType.CHART_RECOMMENDATIONS,
null,
searchId
);
searchId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

/**
*
* 라이브러리 비교
Expand All @@ -22,8 +20,6 @@ public class FastLibraryRequestDTO {
public static class LibraryCompare{
private Long libraryId1;
private Long libraryId2;
private List<String> panelIds1;
private List<String> panelIds2;
}

}
Loading
Loading