From 8784c2436b0e284c74659a5780d70b703d01afa3 Mon Sep 17 00:00:00 2001 From: Lee junbeom Date: Thu, 11 Jul 2024 20:40:16 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A9=98=ED=8A=B8=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EC=8B=9C=20=EA=BD=83=20=ED=9B=84=EB=B3=B4=20=EC=84=B8=20?= =?UTF-8?q?=EA=B0=9C=20=EB=B0=98=ED=99=98=20api=20=EB=AA=A8=EB=8D=B8?= =?UTF-8?q?=EC=84=9C=EB=B2=84=EC=99=80=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ModelController.java | 20 ++----------------- .../domain/inputMessage/dto/MentDto.java | 8 ++++---- .../dto/ModelMentResponseDto.java | 9 ++++++++- .../dto/RecommendationResponse.java | 19 ++++++++++++++++++ .../global/api/service/CallApiService.java | 7 +++++-- 5 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/example/fiurinee/domain/inputMessage/dto/RecommendationResponse.java diff --git a/src/main/java/com/example/fiurinee/domain/inputMessage/controller/ModelController.java b/src/main/java/com/example/fiurinee/domain/inputMessage/controller/ModelController.java index dd2e136..cc4f30d 100644 --- a/src/main/java/com/example/fiurinee/domain/inputMessage/controller/ModelController.java +++ b/src/main/java/com/example/fiurinee/domain/inputMessage/controller/ModelController.java @@ -30,7 +30,7 @@ public ResponseEntity> inputMent(@PathVariable("id") Long @RequestBody RequestMentDto mentDto){ String ment = mentDto.ment(); inputMessageService.saveInputMessage(id, ment); - String url = "http://localhost:8080/model/test"; + String url = "http://3.106.186.161/api/recommend"; int value = LocalDateTime.now().getMonth().getValue(); @@ -56,7 +56,7 @@ public ResponseEntity> inputMent(@PathVariable("id") Long @PostMapping("/ment") public ResponseEntity> inputMentNotMember(@RequestBody String ment){ - String url = "http://localhost:8080/model/test"; + String url = "http://3.106.186.161/api/recommend"; int value = LocalDateTime.now().getMonth().getValue(); @@ -107,20 +107,4 @@ public ResponseEntity selectFlowerNonMember(@PathVar return ResponseEntity.ok(new ResponseHarmonyWitnMentDto("추천은 recommend, recommend는 영어로 추천, 내 너무 피곤하다,, 인생이란 뭘까",re)); } - - @PostMapping("/test") - public List modelTest(@RequestBody MentDto mentDto) { - List re = new ArrayList<>(); - ModelMentResponseDto modelMentResponseDto0 = new ModelMentResponseDto("토레니아", "가련한 욕망"); - ModelMentResponseDto modelMentResponseDto1 = new ModelMentResponseDto("토마토", "완성된 아름다움"); - ModelMentResponseDto modelMentResponseDto2 = new ModelMentResponseDto("겹 캄파눌라", "따뜻한 사람"); - - - re.add(modelMentResponseDto0); - re.add(modelMentResponseDto1); - re.add(modelMentResponseDto2); - - return re; - - } } diff --git a/src/main/java/com/example/fiurinee/domain/inputMessage/dto/MentDto.java b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/MentDto.java index 6434e6d..5ca5bc4 100644 --- a/src/main/java/com/example/fiurinee/domain/inputMessage/dto/MentDto.java +++ b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/MentDto.java @@ -7,13 +7,13 @@ @Getter public class MentDto { - private String ment; - private int month; + private String user_input; + private int user_month; public MentDto(){} public MentDto(String ment, int month) { - this.ment = ment; - this.month = month; + this.user_input = ment; + this.user_month = month; } } diff --git a/src/main/java/com/example/fiurinee/domain/inputMessage/dto/ModelMentResponseDto.java b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/ModelMentResponseDto.java index ffa509a..9330c1c 100644 --- a/src/main/java/com/example/fiurinee/domain/inputMessage/dto/ModelMentResponseDto.java +++ b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/ModelMentResponseDto.java @@ -1,17 +1,24 @@ package com.example.fiurinee.domain.inputMessage.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; @Getter public class ModelMentResponseDto { - + @JsonProperty("꽃") private String name; + + @JsonProperty("꽃말") private String flowerLanguage; + @JsonProperty("유사도") + private Double similarity; + public ModelMentResponseDto(){} public ModelMentResponseDto(String name, String flowerLanguage) { this.name = name; this.flowerLanguage = flowerLanguage; + this.similarity = 0.1; } } diff --git a/src/main/java/com/example/fiurinee/domain/inputMessage/dto/RecommendationResponse.java b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/RecommendationResponse.java new file mode 100644 index 0000000..4dfe75d --- /dev/null +++ b/src/main/java/com/example/fiurinee/domain/inputMessage/dto/RecommendationResponse.java @@ -0,0 +1,19 @@ +package com.example.fiurinee.domain.inputMessage.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +import java.util.List; + +@Getter +public class RecommendationResponse { + @JsonProperty("recommendations") + private List recommendations; + + public RecommendationResponse() {} + + public RecommendationResponse(List recommendations) { + this.recommendations = recommendations; + } +} + diff --git a/src/main/java/com/example/fiurinee/global/api/service/CallApiService.java b/src/main/java/com/example/fiurinee/global/api/service/CallApiService.java index bf31446..2ce993d 100644 --- a/src/main/java/com/example/fiurinee/global/api/service/CallApiService.java +++ b/src/main/java/com/example/fiurinee/global/api/service/CallApiService.java @@ -2,6 +2,7 @@ import com.example.fiurinee.domain.inputMessage.dto.MentDto; import com.example.fiurinee.domain.inputMessage.dto.ModelMentResponseDto; +import com.example.fiurinee.domain.inputMessage.dto.RecommendationResponse; import com.example.fiurinee.domain.inputMessage.dto.ResponseMentDto; import com.example.fiurinee.domain.member.entity.Member; import com.example.fiurinee.domain.oauth2.dto.KakaoLogoutDto; @@ -13,6 +14,7 @@ import org.springframework.web.reactive.function.client.WebClient; import java.util.List; +import java.util.Objects; @Service @Transactional @@ -72,14 +74,15 @@ public static List mentApi(String url, MentDto mentDto) { WebClient webClient = WebClient.builder().build(); - return webClient + RecommendationResponse response = webClient .post() .uri(url) .contentType(MediaType.APPLICATION_JSON) .bodyValue(mentDto) .retrieve() - .bodyToMono(new ParameterizedTypeReference>() {}) + .bodyToMono(RecommendationResponse.class) .block(); + return Objects.requireNonNull(response).getRecommendations(); } }