implement client for meteo weather api
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package SuMoC.backend.meteo;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Service
|
||||
public class MeteoClient {
|
||||
|
||||
private final WebClient meteoClient;
|
||||
|
||||
public MeteoClient(@Qualifier("meteoWebClient") WebClient meteoClient) {
|
||||
this.meteoClient = meteoClient;
|
||||
}
|
||||
|
||||
public Mono<ForecastResponse> getForecastWeatherCodeToday(
|
||||
double lat,
|
||||
double lon
|
||||
) {
|
||||
String today = LocalDate.now().toString(); // Uses ISO-8601 format: yyyy-MM-dd
|
||||
|
||||
return meteoClient.get()
|
||||
.uri(uriBuilder -> uriBuilder.path("/forecast")
|
||||
.queryParam("latitude", lat)
|
||||
.queryParam("longitude", lon)
|
||||
.queryParam("hourly", "weather_code")
|
||||
.queryParam("start_date", today)
|
||||
.queryParam("end_date", today)
|
||||
.build())
|
||||
.retrieve()
|
||||
.bodyToMono(ForecastResponse.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user