From f86a61b741675743175b91bb96784194b4033e49 Mon Sep 17 00:00:00 2001 From: versatile0010 Date: Sun, 8 Oct 2023 03:09:45 +0900 Subject: [PATCH] feat: ai model connect --- .../domain/diet/service/DietService.java | 11 ++++++----- .../example/kusitmshackthon/support/APIOpenFeign.java | 8 ++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/kusitmshackthon/domain/diet/service/DietService.java b/src/main/java/com/example/kusitmshackthon/domain/diet/service/DietService.java index cd9bfad..7f0e6ed 100644 --- a/src/main/java/com/example/kusitmshackthon/domain/diet/service/DietService.java +++ b/src/main/java/com/example/kusitmshackthon/domain/diet/service/DietService.java @@ -17,7 +17,6 @@ import com.example.kusitmshackthon.exception.notfound.FoodInfoNotFoundException; import com.example.kusitmshackthon.exception.notfound.MemberNotFoundException; import com.example.kusitmshackthon.support.APIOpenFeign; -import com.example.kusitmshackthon.support.dto.response.FlaskResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -49,9 +48,11 @@ public ImageUploadResponse analysUserDiet(MultipartFile image, Long userId) { Diet diet = dietRepository.save(Diet.of(member)); // ai 모델로부터 얻어낸 음식 리스트 get - FlaskResponse response = apiOpenFeign.call(image); + String response = apiOpenFeign.call(image); - List foodNameList = response.getFoodNameList(); + List foodNameList = new ArrayList<>(); + foodNameList.add(response); + //List foodNameList = response.getFoodNameList(); List foodEntities = new ArrayList<>(); for (String foodName : foodNameList) { @@ -140,9 +141,9 @@ public GetDietResponse getDietDetails(Long dietId) { Float diff = entry.getValue(); if (diff >= 0) { - enoughList.add(GetDietResponse.NutrientInfo.of(name, accuHm.get(name), diff)); + enoughList.add(GetDietResponse.NutrientInfo.of(name, accuHm.get(name), diff)); } else { - lackList.add(GetDietResponse.NutrientInfo.of(name, accuHm.get(name), diff)); + lackList.add(GetDietResponse.NutrientInfo.of(name, accuHm.get(name), diff)); } } return GetDietResponse.of(lackList, enoughList); diff --git a/src/main/java/com/example/kusitmshackthon/support/APIOpenFeign.java b/src/main/java/com/example/kusitmshackthon/support/APIOpenFeign.java index 6a476e7..77e9d57 100644 --- a/src/main/java/com/example/kusitmshackthon/support/APIOpenFeign.java +++ b/src/main/java/com/example/kusitmshackthon/support/APIOpenFeign.java @@ -2,19 +2,15 @@ import com.example.kusitmshackthon.support.dto.response.FlaskResponse; import feign.Headers; -import feign.form.ContentType; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; -import java.util.Map; - -@FeignClient(name = "APIOpenFeign", url = "http://localhost:8080/api/diet/test") // todo: setting +@FeignClient(name = "APIOpenFeign", url = "${myapi.path}") // todo: setting public interface APIOpenFeign { @Headers("Content-Type: multipart/form-data") @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - FlaskResponse call(@RequestPart(value = "image") MultipartFile image); + String call(@RequestPart(value = "image") MultipartFile image); }