prototypical wrapper for carta client
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package SuMoC.backend.carta;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import sumoc.backend.carta.client.api.MapApi;
|
||||
import sumoc.backend.carta.client.invoker.ApiException;
|
||||
import sumoc.backend.carta.client.model.Direction;
|
||||
|
||||
@Service
|
||||
public class CartaClient {
|
||||
|
||||
private final MapApi mapApi;
|
||||
|
||||
public CartaClient(MapApi mapApi) {
|
||||
this.mapApi = mapApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param origin
|
||||
* @param destination
|
||||
* @param mode
|
||||
* @param arrivalTime
|
||||
* @param departureTime
|
||||
* @param alternatives Number of alternatives
|
||||
* @param walkingSpeed
|
||||
* @param transferTime
|
||||
* @param accessible
|
||||
* @param parking
|
||||
* @param type 0=tram, 1=subway, 2=rail, 3=bus, 4=ferry, 5=cablecar, 6=gondola, 7=funicular, 8=trolleybus, 9=monorail
|
||||
* @param range
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
public Direction getRoute(
|
||||
String origin,
|
||||
String destination,
|
||||
String mode,
|
||||
Long arrivalTime,
|
||||
Long departureTime,
|
||||
Integer alternatives,
|
||||
Double walkingSpeed,
|
||||
Integer transferTime,
|
||||
Boolean accessible,
|
||||
Boolean parking,
|
||||
String type,
|
||||
Integer range,
|
||||
String location
|
||||
) {
|
||||
try {
|
||||
String uid = null; // Optional user identifier
|
||||
return mapApi.getDirection(
|
||||
origin,
|
||||
destination,
|
||||
mode,
|
||||
arrivalTime,
|
||||
departureTime,
|
||||
alternatives,
|
||||
walkingSpeed,
|
||||
transferTime,
|
||||
accessible,
|
||||
parking,
|
||||
type,
|
||||
range,
|
||||
location,
|
||||
uid
|
||||
);
|
||||
} catch (ApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package SuMoC.backend.carta;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import sumoc.backend.carta.client.api.MapApi;
|
||||
import sumoc.backend.carta.client.invoker.ApiClient;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(CartaProperties.class)
|
||||
public class CartaClientConfig {
|
||||
|
||||
@Bean
|
||||
public ApiClient cartaApiClient(CartaProperties cartaProperties) {
|
||||
ApiClient apiClient = new ApiClient();
|
||||
apiClient.setBasePath(cartaProperties.baseUrl());
|
||||
// TODO Timeouts?
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MapApi mapApi(ApiClient cartaApiClient) {
|
||||
return new MapApi(cartaApiClient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package SuMoC.backend.carta;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "carta")
|
||||
public record CartaProperties(
|
||||
String baseUrl
|
||||
) {
|
||||
}
|
||||
Reference in New Issue
Block a user