package io.swagger.api; import io.swagger.model.Modelforecast; import io.swagger.model.Modelforecast; import io.swagger.model.Modelforecast; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import javax.validation.constraints.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.List; import java.util.Map; @javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2024-06-04T09:41:03.559554872Z[GMT]") @RestController public class ForecastweatherApiController implements ForecastweatherApi { private static final Logger log = LoggerFactory.getLogger(ForecastweatherApiController.class); private final ObjectMapper objectMapper; private final HttpServletRequest request; @org.springframework.beans.factory.annotation.Autowired public ForecastweatherApiController(ObjectMapper objectMapper, HttpServletRequest request) { this.objectMapper = objectMapper; this.request = request; } public ResponseEntity 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, @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", required = false, schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter) { try { String datafree = "{\"location\":{},\"current\": {\"condition\": {},\"air_quality\": {}}}"; RestTemplate restTemplate = new RestTemplate(); ApiService apiService = new ApiService(restTemplate); String data = apiService.getDataFromFirstApi( "https://api.weatherapi.com/v1/forecast.json?key=1244099aeaee4b179e6111803241304&q=" + q + "&days=" + days + "&aqi=yes&alerts=" + alerts); ResponseEntity response = new ResponseEntity(objectMapper.readValue( data, Modelforecast.class), HttpStatus.ACCEPTED); ResponseEntity response2 = new ResponseEntity(objectMapper.readValue( datafree, Modelforecast.class), HttpStatus.ACCEPTED); String[] filterlist = filter.split(","); return response2; } catch (IOException e) { log.error("Couldn't serialize response for content type application/json", e); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } } }