Skip to content

Commit

Permalink
[feat] 채팅 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Feb 27, 2024
1 parent b6b1cb0 commit 21b563e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.garam.garam_e_spring.global.response.BaseResponseDto;
import com.garam.garam_e_spring.global.response.ErrorMessage;
import com.google.gson.Gson;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -16,9 +18,11 @@
@Slf4j
@RestController
@RequestMapping("/api/chat")
@RequiredArgsConstructor
public class ChatController {

private final String flaskUrl = "http://localhost:5000";
@Value("${flask.url}")
private String flaskUrl;

@PostMapping("")
public BaseResponseDto<ChatResponseDto.Chat> chat(
Expand All @@ -34,9 +38,9 @@ public BaseResponseDto<ChatResponseDto.Chat> chat(
HttpEntity<String> req = new HttpEntity<>(gson.toJson(request), headers);

RestTemplate restTemplate = new RestTemplate();
String flaskResponse = restTemplate.postForObject(flaskUrl + "/chat", req, String.class);
ChatResponseDto.Chat flaskResponse = restTemplate.getForObject(flaskUrl + "/get-question/" + request.getMessage(), ChatResponseDto.Chat.class, req);
log.info("flaskResponse: {}", flaskResponse);
return new BaseResponseDto<>(new ChatResponseDto.Chat(flaskResponse));
return new BaseResponseDto<>(flaskResponse);
} catch (Exception e) {
log.info(e.getMessage());
return new BaseResponseDto<>(ErrorMessage.INTERVAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;

public class ChatResponseDto {

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class Chat {
private String message;
private String answer;
private ArrayList<String> button_name;
private ArrayList<String> link;
private String question;
}
}

0 comments on commit 21b563e

Please sign in to comment.