소스정리
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package net.jwsi.jcms_vpp.common.client;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.jwsi.jcms_vpp.Api.ApiResponse;
|
||||
import net.jwsi.jcms_vpp.station.StationDto;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ApiClient {
|
||||
|
||||
private final RestClient restClient;
|
||||
|
||||
public ApiResponse<List<StationDto>> fetchStations(String baseUrl, String token) {
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl)
|
||||
.path("/api/station/list")
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
return restClient.get()
|
||||
.uri(uri)
|
||||
.header("Authorization", "Bearer " + token)
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<ApiResponse<List<StationDto>>>() {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.jwsi.jcms_vpp.Api;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiResponse<T> {
|
||||
private Integer code;
|
||||
private String httpStatus;
|
||||
private String message;
|
||||
private List<T> data;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.jwsi.jcms_vpp.global.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Configuration
|
||||
public class RestClientConfig {
|
||||
|
||||
@Bean
|
||||
public RestClient restClient() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setConnectTimeout((int) Duration.ofSeconds(5).toMillis());
|
||||
factory.setReadTimeout((int) Duration.ofSeconds(10).toMillis());
|
||||
|
||||
return RestClient.builder()
|
||||
.requestFactory(factory)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.jwsi.jcms_vpp.station;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StationDto {
|
||||
private String providerId;
|
||||
private String providerNm;
|
||||
private String bizTaxId;
|
||||
private String ceo;
|
||||
private String tel;
|
||||
private String fax;
|
||||
private String email;
|
||||
private String zipCode;
|
||||
private String addr;
|
||||
}
|
||||
Reference in New Issue
Block a user