Skip to content

Commit

Permalink
Refactor: 동일한 레시피 추천 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
bingseok committed Feb 18, 2025
1 parent a61ecaa commit 67e30f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public RecipeResponseDTO.RecipePageResponse searchRecipes(String ingredients, in
int totalPages = (int) Math.ceil((double) totalElements / size);

String url = buildApiUrl(ingredients, startIdx, endIdx);

System.out.println("url: " + url);
RecipeResponseDTO.RecipeApiResponse apiResponse = restTemplate.getForObject(url, RecipeResponseDTO.RecipeApiResponse.class);

List<RecipeResponseDTO.RecipeResponse> recipes = apiResponse.getRecipes().stream()
Expand Down Expand Up @@ -229,10 +229,15 @@ private String buildApiUrl(String recipeName) {

// 페이징용 URL 생성
private String buildApiUrl(String ingredients, int startIdx, int endIdx) {
return UriComponentsBuilder.fromHttpUrl("http://openapi.foodsafetykorea.go.kr/api")

String quotedName = "\"" + ingredients + "\"";
String baseUrl = "http://openapi.foodsafetykorea.go.kr/api/" + keyId + "/COOKRCP01/json/" + startIdx + "/" + endIdx;
return baseUrl + "/RCP_PARTS_DTLS=" + quotedName;

/*return UriComponentsBuilder.fromHttpUrl("http://openapi.foodsafetykorea.go.kr/api")
.pathSegment(keyId, "COOKRCP01", "json", String.valueOf(startIdx), String.valueOf(endIdx))
.queryParam("RCP_PARTS_DTLS", ingredients)
.toUriString();
.toUriString();*/
}

private String cleanIngredients(String ingredients) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public ApiResponse<RecipeResponseDTO.RecipePageResponse> recommendRecipesByIngre
@RequestParam(defaultValue = "10") int size
){
RecipeResponseDTO.RecipePageResponse recipes = recipeService.searchRecipes(ingredients, page, size);
System.out.println("ingre: " + ingredients);
return ApiResponse.onSuccess(SuccessStatus.RECIPE_RECOMMEND_OK, recipes);
}

Expand Down

0 comments on commit 67e30f1

Please sign in to comment.