Skip to content

Commit

Permalink
feat: 멘트 입력시 꽃 후보 세 개 반환 api 모델서버와 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
ss7622 committed Jul 11, 2024
1 parent 4075b2e commit 8784c24
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ResponseEntity<List<ResponseMentDto>> 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();

Expand All @@ -56,7 +56,7 @@ public ResponseEntity<List<ResponseMentDto>> inputMent(@PathVariable("id") Long

@PostMapping("/ment")
public ResponseEntity<List<ResponseMentDto>> 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();

Expand Down Expand Up @@ -107,20 +107,4 @@ public ResponseEntity<ResponseHarmonyWitnMentDto> selectFlowerNonMember(@PathVar

return ResponseEntity.ok(new ResponseHarmonyWitnMentDto("추천은 recommend, recommend는 영어로 추천, 내 너무 피곤하다,, 인생이란 뭘까",re));
}

@PostMapping("/test")
public List<ModelMentResponseDto> modelTest(@RequestBody MentDto mentDto) {
List<ModelMentResponseDto> 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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ModelMentResponseDto> recommendations;

public RecommendationResponse() {}

public RecommendationResponse(List<ModelMentResponseDto> recommendations) {
this.recommendations = recommendations;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;
import java.util.Objects;

@Service
@Transactional
Expand Down Expand Up @@ -72,14 +74,15 @@ public static List<ModelMentResponseDto> 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<List<ModelMentResponseDto>>() {})
.bodyToMono(RecommendationResponse.class)
.block();
return Objects.requireNonNull(response).getRecommendations();

}
}

0 comments on commit 8784c24

Please sign in to comment.