Commit a454f48f authored by EnesKarakas's avatar EnesKarakas
Browse files

jes

parent 9d889c8b
...@@ -56,9 +56,11 @@ public class CurrentweatherApiController implements CurrentweatherApi { ...@@ -56,9 +56,11 @@ public class CurrentweatherApiController implements CurrentweatherApi {
String datafree = "{\"location\":{},\"current\": {\"condition\": {},\"air_quality\": {}}}"; String datafree = "{\"location\":{},\"current\": {\"condition\": {},\"air_quality\": {}}}";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
ApiService apiService = new ApiService(restTemplate); ApiService apiService = new ApiService(restTemplate);
String data = apiService.getDataFromFirstApi( String data = apiService.getDataFromFirstApi(
"https://api.weatherapi.com/v1/current.json?key=1244099aeaee4b179e6111803241304&q=" + q "https://api.weatherapi.com/v1/current.json?key=1244099aeaee4b179e6111803241304&q=" + q
+ "&aqi=yes"); + "&aqi=yes");
ResponseEntity<Model200> response = new ResponseEntity<Model200>(objectMapper.readValue( ResponseEntity<Model200> response = new ResponseEntity<Model200>(objectMapper.readValue(
data, Model200.class), HttpStatus.ACCEPTED); data, Model200.class), HttpStatus.ACCEPTED);
ResponseEntity<Model200> response2 = new ResponseEntity<Model200>(objectMapper.readValue( ResponseEntity<Model200> response2 = new ResponseEntity<Model200>(objectMapper.readValue(
......
...@@ -47,6 +47,11 @@ public interface ForecastweatherApi { ...@@ -47,6 +47,11 @@ public interface ForecastweatherApi {
"text/plain" }, method = RequestMethod.GET) "text/plain" }, method = RequestMethod.GET)
ResponseEntity<Modelforecast> forecastWeatherData( ResponseEntity<Modelforecast> forecastWeatherData(
@NotNull @Parameter(in = ParameterIn.QUERY, description = "For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.", required = true, schema = @Schema()) @Valid @RequestParam(value = "q", required = true) String q, @NotNull @Parameter(in = ParameterIn.QUERY, description = "For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.", required = true, schema = @Schema()) @Valid @RequestParam(value = "q", required = true) String q,
@Parameter(in = ParameterIn.QUERY, description = "forcast days", schema = @Schema()) @Valid @RequestParam(value = "days", required = true) int days,
@Parameter(in = ParameterIn.QUERY, description = "show alerts", schema = @Schema()) @Valid @RequestParam(value = "alerts", required = true) String alerts,
@Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter); @Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter);
} }
package io.swagger.api; package io.swagger.api;
import io.swagger.model.Modelforecast;
import io.swagger.model.Modelforecast; import io.swagger.model.Modelforecast;
import io.swagger.model.Modelforecast; import io.swagger.model.Modelforecast;
...@@ -53,18 +54,30 @@ public class ForecastweatherApiController implements ForecastweatherApi { ...@@ -53,18 +54,30 @@ public class ForecastweatherApiController implements ForecastweatherApi {
public ResponseEntity<Modelforecast> forecastWeatherData( public ResponseEntity<Modelforecast> forecastWeatherData(
@NotNull @Parameter(in = ParameterIn.QUERY, description = "For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.", required = true, schema = @Schema()) @Valid @RequestParam(value = "q", required = true) String q, @NotNull @Parameter(in = ParameterIn.QUERY, description = "For the query value, type the city name and optionally the country code divided by comma; use ISO 3166 country codes.", required = true, schema = @Schema()) @Valid @RequestParam(value = "q", required = true) String q,
@Parameter(in = ParameterIn.QUERY, description = "forcast days", required = true, schema = @Schema()) @Valid @RequestParam(value = "days", required = true) int days,
@Parameter(in = ParameterIn.QUERY, description = "shows alerts", required = true, schema = @Schema()) @Valid @RequestParam(value = "alerts", required = true) String alerts,
@Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter) { @Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter) {
try { try {
String datafree = "{\"location\":{},\"current\": {\"condition\": {},\"air_quality\": {}}}";
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
ApiService apiService = new ApiService(restTemplate); ApiService apiService = new ApiService(restTemplate);
String data = apiService.getDataFromFirstApi( String data = apiService.getDataFromFirstApi(
"https://api.weatherapi.com/v1/forecast.json?key=1244099aeaee4b179e6111803241304&q=" + q "https://api.weatherapi.com/v1/forecast.json?key=1244099aeaee4b179e6111803241304&q=" + q
+ "&days=1&aqi=yes&alerts=yes"); + "&days=" + days + "&aqi=yes&alerts=" + alerts);
System.out.println(data);
ResponseEntity<Modelforecast> response = new ResponseEntity<Modelforecast>(objectMapper.readValue( ResponseEntity<Modelforecast> response = new ResponseEntity<Modelforecast>(objectMapper.readValue(
data, Modelforecast.class), HttpStatus.ACCEPTED); data, Modelforecast.class), HttpStatus.ACCEPTED);
return response; ResponseEntity<Modelforecast> response2 = new ResponseEntity<Modelforecast>(objectMapper.readValue(
datafree, Modelforecast.class), HttpStatus.ACCEPTED);
String[] filterlist = filter.split(",");
return response2;
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<Modelforecast>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<Modelforecast>(HttpStatus.INTERNAL_SERVER_ERROR);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment