[KC-108] ai api 실행

This commit is contained in:
2026-01-12 18:48:59 +09:00
parent ad0c3bc080
commit 546981076c
3 changed files with 25 additions and 17 deletions

View File

@@ -14,17 +14,18 @@ public class ExternalHttpClient {
private final RestTemplate restTemplate;
public ResponseEntity<String> exchange(
String url, HttpMethod method, Object body, HttpHeaders headers) {
public <T> ResponseEntity<T> exchange(
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
return restTemplate.exchange(url, method, entity, String.class);
return restTemplate.exchange(url, method, entity, responseType);
}
public ExternalCallResult call(String url, HttpMethod method, Object body, HttpHeaders headers) {
ResponseEntity<String> res = exchange(url, method, body, headers);
public <T> ExternalCallResult<T> call(
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
ResponseEntity<T> res = exchange(url, method, body, headers, responseType);
int code = res.getStatusCodeValue();
return new ExternalCallResult(code, code >= 200 && code < 300, res.getBody());
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
}
public record ExternalCallResult(int statusCode, boolean success, String body) {}
public record ExternalCallResult<T>(int statusCode, boolean success, T body) {}
}