Commit 9d889c8b authored by EnesKarakas's avatar EnesKarakas
Browse files

new backend

parent 888289d4
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
3.0.57
\ No newline at end of file
# Swagger generated server
Spring Boot Server
## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project.
By using the [OpenAPI-Spec](https://github.com/swagger-api/swagger-core), you can easily generate a server stub.
This is an example of building a swagger-enabled server in Java using the SpringBoot framework.
The underlying library integrating swagger to SpringBoot is [springdoc-openapi](https://github.com/springdoc/springdoc-openapi)
Start your server as an simple java application
You can view the api documentation in swagger-ui by pointing to
http://localhost:8080/
Change default port value in application.properties
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-spring</artifactId>
<packaging>jar</packaging>
<name>swagger-spring</name>
<version>1.0.0</version>
<properties>
<java.version>1.7</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springdoc-version>1.7.0</springdoc-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
<version>2.1.16.RELEASE</version>
</parent>
<groupId>com.SWP.SS24</groupId>
<artifactId>Wetterdaten.sammeln</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Wetterdaten.sammeln</name>
<description>Wetterdaten aus dem Netz sammeln und speichern.</description>
<properties>
<java.version>21</java.version>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!--SpringFox dependencies -->
<!-- SpringDoc dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>2.6.4</version>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
</dependencies>
</project>
package com.SWP.SS24.Wetterdaten_sammeln;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package com.SWP.SS24.Wetterdaten_sammeln.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class historicData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
}
package io.swagger;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
import java.text.FieldPosition;
import java.util.Date;
public class RFC3339DateFormat extends ISO8601DateFormat {
private static final long serialVersionUID = 1L;
// Same as ISO8601DateFormat but serializing milliseconds.
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
String value = ISO8601Utils.format(date, true);
toAppendTo.append(value);
return toAppendTo;
}
}
\ No newline at end of file
package io.swagger;
import io.swagger.configuration.LocalDateConverter;
import io.swagger.configuration.LocalDateTimeConverter;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@SpringBootApplication
@ComponentScan(basePackages = { "io.swagger", "io.swagger.api" , "io.swagger.configuration"})
public class Swagger2SpringBoot implements CommandLineRunner {
@Override
public void run(String... arg0) throws Exception {
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
throw new ExitException();
}
}
public static void main(String[] args) throws Exception {
new SpringApplication(Swagger2SpringBoot.class).run(args);
}
@Configuration
static class CustomDateConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateConverter("yyyy-MM-dd"));
registry.addConverter(new LocalDateTimeConverter("yyyy-MM-dd'T'HH:mm:ss.SSS"));
}
}
class ExitException extends RuntimeException implements ExitCodeGenerator {
private static final long serialVersionUID = 1L;
@Override
public int getExitCode() {
return 10;
}
}
}
package io.swagger.api;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2024-06-04T09:41:03.559554872Z[GMT]")
public class ApiException extends Exception {
@SuppressWarnings("unused")
private int code;
public ApiException(int code, String msg) {
super(msg);
this.code = code;
}
}
package io.swagger.api;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2024-06-04T09:41:03.559554872Z[GMT]")
public class ApiOriginFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
package io.swagger.api;
import javax.xml.bind.annotation.XmlTransient;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2024-06-04T09:41:03.559554872Z[GMT]")
@javax.xml.bind.annotation.XmlRootElement
public class ApiResponseMessage {
public static final int ERROR = 1;
public static final int WARNING = 2;
public static final int INFO = 3;
public static final int OK = 4;
public static final int TOO_BUSY = 5;
int code;
String type;
String message;
public ApiResponseMessage(){}
public ApiResponseMessage(int code, String message){
this.code = code;
switch(code){
case ERROR:
setType("error");
break;
case WARNING:
setType("warning");
break;
case INFO:
setType("info");
break;
case OK:
setType("ok");
break;
case TOO_BUSY:
setType("too busy");
break;
default:
setType("unknown");
break;
}
this.message = message;
}
@XmlTransient
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package io.swagger.api;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.http.ResponseEntity;
public class ApiService {
private final RestTemplate restTemplate;
public ApiService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public String getDataFromFirstApi(String apiUrl) {
ResponseEntity<String> response = restTemplate.getForEntity(apiUrl, String.class);
return response.getBody();
}
}
/**
* NOTE: This class is auto generated by the swagger code generator program (3.0.57).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package io.swagger.api;
import io.swagger.model.Model200;
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.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.CookieValue;
import javax.validation.Valid;
import javax.validation.constraints.*;
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]")
@Validated
public interface CurrentweatherApi {
@Operation(summary = "Call current weather data for one location", description = "Get the current weather info", tags={ "Current Weather Data" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model200.class))),
@ApiResponse(responseCode = "404", description = "Not found response", content = @Content(mediaType = "text/plain", schema = @Schema(implementation = String.class))) })
@RequestMapping(value = "/currentweather",
produces = { "application/json", "text/plain" },
method = RequestMethod.GET)
ResponseEntity<Model200> currentWeatherData(@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 = "filter parameter" ,schema=@Schema()) @Valid @RequestParam(value = "filter", required = false) String filter
);
}
package io.swagger.api;
import io.swagger.model.Model200;
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 CurrentweatherApiController implements CurrentweatherApi {
private static final Logger log = LoggerFactory.getLogger(CurrentweatherApiController.class);
private final ObjectMapper objectMapper;
private final HttpServletRequest request;
@org.springframework.beans.factory.annotation.Autowired
public CurrentweatherApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.objectMapper = objectMapper;
this.request = request;
}
public ResponseEntity<Model200> currentWeatherData(
@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 = "filter parameter", 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/current.json?key=1244099aeaee4b179e6111803241304&q=" + q
+ "&aqi=yes");
ResponseEntity<Model200> response = new ResponseEntity<Model200>(objectMapper.readValue(
data, Model200.class), HttpStatus.ACCEPTED);
ResponseEntity<Model200> response2 = new ResponseEntity<Model200>(objectMapper.readValue(
datafree, Model200.class), HttpStatus.ACCEPTED);
String[] filterlist = filter.split(",");
for (String filterindex : filterlist) {
switch (filterindex) {
case "last_updated_epoch":
response2.getBody().getCurrent()
.setLastUpdatedEpoch(response.getBody().getCurrent().getLastUpdatedEpoch());
break;
case "last_updated":
response2.getBody().getCurrent()
.setLastUpdated(response.getBody().getCurrent().getLastUpdated());
break;
case "temp_c":
response2.getBody().getCurrent().setTempC(response.getBody().getCurrent().getTempC());
break;
case "temp_f":
response2.getBody().getCurrent().setTempF(response.getBody().getCurrent().getTempF());
break;
case "id_day":
response2.getBody().getCurrent().setIdDay(response.getBody().getCurrent().getIdDay());
break;
case "condition":
response2.getBody().getCurrent().setCondition(response.getBody().getCurrent().getCondition());
break;
case "wind_mph":
response2.getBody().getCurrent().setWindMph(response.getBody().getCurrent().getWindMph());
break;
case "wind_kph":
response2.getBody().getCurrent().setWindKph(response.getBody().getCurrent().getWindKph());
break;
case "wind_degree":
response2.getBody().getCurrent().setWindDegree(response.getBody().getCurrent().getWindDegree());
break;
case "wind_dir":
response2.getBody().getCurrent().setWindDir(response.getBody().getCurrent().getWindDir());
break;
case "pressure_mb":
response2.getBody().getCurrent().setPressureMb(response.getBody().getCurrent().getPressureMb());
break;
case "pressure_in":
response2.getBody().getCurrent().setPressureIn(response.getBody().getCurrent().getPressureIn());
break;
case "precip_mm":
response2.getBody().getCurrent().setPrecipMm(response.getBody().getCurrent().getPrecipMm());
break;
case "precip_in":
response2.getBody().getCurrent().setPrecipIn(response.getBody().getCurrent().getPrecipIn());
break;
case "humidity":
response2.getBody().getCurrent().setHumidity(response.getBody().getCurrent().getHumidity());
break;
case "cloud":
response2.getBody().getCurrent().setCloud(response.getBody().getCurrent().getCloud());
break;
case "feelslike_c":
response2.getBody().getCurrent().setFeelslikeC(response.getBody().getCurrent().getFeelslikeC());
break;
case "feelslike_f":
response2.getBody().getCurrent().setFeelslikeF(response.getBody().getCurrent().getFeelslikeF());
break;
case "windchill_c":
response2.getBody().getCurrent().setWindchillC(response.getBody().getCurrent().getWindchillC());
break;
case "windchill_f":
response2.getBody().getCurrent().setWindchillF(response.getBody().getCurrent().getWindchillF());
break;
case "heatindex_c":
response2.getBody().getCurrent().setHeatindexC(response.getBody().getCurrent().getHeatindexC());
break;
case "heatindex_f":
response2.getBody().getCurrent().setHeatindexF(response.getBody().getCurrent().getHeatindexF());
break;
case "dewpoint_c":
response2.getBody().getCurrent().setDewpointC(response.getBody().getCurrent().getDewpointC());
break;
case "dewpoint_f":
response2.getBody().getCurrent().setDewpointF(response.getBody().getCurrent().getDewpointF());
break;
case "vis_km":
response2.getBody().getCurrent().setVisKm(response.getBody().getCurrent().getVisKm());
break;
case "vis_miles":
response2.getBody().getCurrent().setVisMiles(response.getBody().getCurrent().getVisMiles());
break;
case "uv":
response2.getBody().getCurrent().setUv(response.getBody().getCurrent().getUv());
break;
case "gust_mph":
response2.getBody().getCurrent().setGustMph(response.getBody().getCurrent().getGustMph());
break;
case "gust_kph":
response2.getBody().getCurrent().setGustKph(response.getBody().getCurrent().getGustKph());
break;
case "air_quality":
response2.getBody().getCurrent().setAirQuality(response.getBody().getCurrent().getAirQuality());
break;
case "name":
response2.getBody().getLocation().setName(response.getBody().getLocation().getName());
break;
case "region":
response2.getBody().getLocation().setRegion(response.getBody().getLocation().getRegion());
break;
case "country":
response2.getBody().getLocation().setCountry(response.getBody().getLocation().getCountry());
break;
case "lon":
response2.getBody().getLocation().setLon(response.getBody().getLocation().getLon());
break;
case "lat":
response2.getBody().getLocation().setLat(response.getBody().getLocation().getLat());
break;
case "tz_id":
response2.getBody().getLocation().setTzId(response.getBody().getLocation().getTzId());
break;
case "localtime_epoch":
response2.getBody().getLocation()
.setLocaltimeEpoch(response.getBody().getLocation().getLocaltimeEpoch());
break;
case "localtime":
response2.getBody().getLocation().setLocaltime(response.getBody().getLocation().getLocaltime());
break;
case "co":
response2.getBody().getCurrent().getAirQuality()
.setCo(response.getBody().getCurrent().getAirQuality().getCo());
break;
case "no2":
response2.getBody().getCurrent().getAirQuality()
.setNo2(response.getBody().getCurrent().getAirQuality().getNo2());
break;
case "o3":
response2.getBody().getCurrent().getAirQuality()
.setO3(response.getBody().getCurrent().getAirQuality().getO3());
break;
case "so2":
response2.getBody().getCurrent().getAirQuality()
.setSo2(response.getBody().getCurrent().getAirQuality().getSo2());
break;
case "pm2_5":
response2.getBody().getCurrent().getAirQuality()
.setPm25(response.getBody().getCurrent().getAirQuality().getPm25());
break;
case "pm10":
response2.getBody().getCurrent().getAirQuality()
.setPm10(response.getBody().getCurrent().getAirQuality().getPm10());
break;
case "us-epa-index":
response2.getBody().getCurrent().getAirQuality()
.setUsEpaIndex(response.getBody().getCurrent().getAirQuality().getUsEpaIndex());
break;
case "gb-defra-index":
response2.getBody().getCurrent().getAirQuality()
.setGbDefraIndex(response.getBody().getCurrent().getAirQuality().getGbDefraIndex());
break;
case "text":
response2.getBody().getCurrent().getCondition()
.setText(response.getBody().getCurrent().getCondition().getText());
break;
case "icon":
response2.getBody().getCurrent().getCondition()
.setIcon(response.getBody().getCurrent().getCondition().getIcon());
break;
case "code":
response2.getBody().getCurrent().getCondition()
.setCode(response.getBody().getCurrent().getCondition().getCode());
break;
default:
break;
}
}
return response2;
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<Model200>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
/**
* NOTE: This class is auto generated by the swagger code generator program (3.0.57).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package io.swagger.api;
import io.swagger.model.Model200;
import io.swagger.model.Modelforecast;
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.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.CookieValue;
import javax.validation.Valid;
import javax.validation.constraints.*;
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]")
@Validated
public interface ForecastweatherApi {
@Operation(summary = "Call forecast weather data for one location", description = "Get the forecast weather info", tags = {
"Forecast Weather Data" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model200.class))),
@ApiResponse(responseCode = "404", description = "Not found response", content = @Content(mediaType = "text/plain", schema = @Schema(implementation = String.class))) })
@RequestMapping(value = "/forecastweather", produces = { "application/json",
"text/plain" }, method = RequestMethod.GET)
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,
@Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter);
}
package io.swagger.api;
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<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,
@Parameter(in = ParameterIn.QUERY, description = "filter parameter", schema = @Schema()) @Valid @RequestParam(value = "filter", required = false) String filter) {
try {
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=1&aqi=yes&alerts=yes");
System.out.println(data);
ResponseEntity<Modelforecast> response = new ResponseEntity<Modelforecast>(objectMapper.readValue(
data, Modelforecast.class), HttpStatus.ACCEPTED);
return response;
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<Modelforecast>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
/**
* NOTE: This class is auto generated by the swagger code generator program (3.0.57).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package io.swagger.api;
import io.swagger.model.Model200;
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.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.CookieValue;
import javax.validation.Valid;
import javax.validation.constraints.*;
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]")
@Validated
public interface HistoricalweatherApi {
@Operation(summary = "Call Historical weather data for one location", description = "Get the historical weather info", tags={ "Historical Weather Data" })
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model200.class))),
@ApiResponse(responseCode = "404", description = "Not found response", content = @Content(mediaType = "text/plain", schema = @Schema(implementation = String.class))) })
@RequestMapping(value = "/historicalweather",
produces = { "application/json", "text/plain" },
method = RequestMethod.GET)
ResponseEntity<Model200> historicalWeatherData(@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 = "filter parameter" ,schema=@Schema()) @Valid @RequestParam(value = "filter", required = false) String filter
);
}
package io.swagger.api;
import io.swagger.model.Model200;
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.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 HistoricalweatherApiController implements HistoricalweatherApi {
private static final Logger log = LoggerFactory.getLogger(HistoricalweatherApiController.class);
private final ObjectMapper objectMapper;
private final HttpServletRequest request;
@org.springframework.beans.factory.annotation.Autowired
public HistoricalweatherApiController(ObjectMapper objectMapper, HttpServletRequest request) {
this.objectMapper = objectMapper;
this.request = request;
}
public ResponseEntity<Model200> historicalWeatherData(@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 = "filter parameter" ,schema=@Schema()) @Valid @RequestParam(value = "filter", required = false) String filter
) {
String accept = request.getHeader("Accept");
if (accept != null && accept.contains("application/json")) {
try {
return new ResponseEntity<Model200>(objectMapper.readValue("{\n \"weather\" : {\n \"feelslike_c\" : 803.463,\n \"feelslike_f\" : 803.463,\n \"wind_degree\" : 803234,\n \"windchill_f\" : 803.478,\n \"windchill_c\" : 803.367,\n \"last_updated_epoch\" : 1238213521,\n \"temp_c\" : 8.3,\n \"temp_f\" : 8.8,\n \"cloud\" : 80338,\n \"wind_kph\" : 803.29,\n \"wind_mph\" : 80.39,\n \"humidity\" : 8039,\n \"dewpoint_f\" : 803.38,\n \"uv\" : 803.473,\n \"last_updated\" : \"2001-10-09 10:07\",\n \"id_day\" : 803.29,\n \"heatindex_f\" : 803.736,\n \"dewpoint_c\" : 803.83,\n \"precip_in\" : 803.473,\n \"heatindex_c\" : 803287,\n \"air_quality\" : {\n \"no2\" : 3.4,\n \"o3\" : 234.3,\n \"us-epa-index\" : 32,\n \"so2\" : 490.34,\n \"pm2_5\" : 96.34,\n \"pm10\" : 22.3,\n \"co\" : 234.32,\n \"gb-defra-index\" : 9999\n },\n \"wind_dir\" : \"SSE\",\n \"gust_mph\" : 803.37,\n \"pressure_in\" : 803.3841,\n \"gust_kph\" : 803.3662,\n \"precip_mm\" : 803.438,\n \"condition\" : {\n \"code\" : 1003,\n \"icon\" : \"//cdn.weatherapi.com/weather/64x64/day/116.png\",\n \"text\" : \"overcast\"\n },\n \"vis_km\" : 803.37,\n \"pressure_mb\" : 86.5,\n \"vis_miles\" : 803.48\n },\n \"location\" : {\n \"localtime\" : \"2001-10-09 10:07\",\n \"country\" : \"Germany\",\n \"localtime_epoch\" : 1717491434,\n \"name\" : \"stuttgart\",\n \"lon\" : 48.78,\n \"region\" : \"baden wuerttemberg\",\n \"lat\" : 9.17,\n \"tz_id\" : \"europa/berlin\"\n }\n}", Model200.class), HttpStatus.NOT_IMPLEMENTED);
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<Model200>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
return new ResponseEntity<Model200>(HttpStatus.NOT_IMPLEMENTED);
}
}
package io.swagger.api;
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2024-06-04T09:41:03.559554872Z[GMT]")
public class NotFoundException extends ApiException {
private int code;
public NotFoundException (int code, String msg) {
super(code, msg);
this.code = code;
}
}
package io.swagger.configuration;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonTokenId;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils;
import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase;
import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction;
import com.fasterxml.jackson.datatype.threetenbp.function.Function;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.DateTimeUtils;
import org.threeten.bp.Instant;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
import java.io.IOException;
import java.math.BigDecimal;
/**
* Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime},
* and {@link ZonedDateTime}s.
* Adapted from the jackson threetenbp InstantDeserializer to add support for
* deserializing rfc822 format.
*
* @author Nick Williams
*/
public class CustomInstantDeserializer<T extends Temporal>
extends ThreeTenDateTimeDeserializerBase<T> {
private static final long serialVersionUID = 1L;
public static final CustomInstantDeserializer<Instant> INSTANT = new CustomInstantDeserializer<Instant>(
Instant.class, DateTimeFormatter.ISO_INSTANT,
new Function<TemporalAccessor, Instant>() {
@Override
public Instant apply(TemporalAccessor temporalAccessor) {
return Instant.from(temporalAccessor);
}
},
new Function<FromIntegerArguments, Instant>() {
@Override
public Instant apply(FromIntegerArguments a) {
return Instant.ofEpochMilli(a.value);
}
},
new Function<FromDecimalArguments, Instant>() {
@Override
public Instant apply(FromDecimalArguments a) {
return Instant.ofEpochSecond(a.integer, a.fraction);
}
},
null);
public static final CustomInstantDeserializer<OffsetDateTime> OFFSET_DATE_TIME = new CustomInstantDeserializer<OffsetDateTime>(
OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
new Function<TemporalAccessor, OffsetDateTime>() {
@Override
public OffsetDateTime apply(TemporalAccessor temporalAccessor) {
return OffsetDateTime.from(temporalAccessor);
}
},
new Function<FromIntegerArguments, OffsetDateTime>() {
@Override
public OffsetDateTime apply(FromIntegerArguments a) {
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
}
},
new Function<FromDecimalArguments, OffsetDateTime>() {
@Override
public OffsetDateTime apply(FromDecimalArguments a) {
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
}
},
new BiFunction<OffsetDateTime, ZoneId, OffsetDateTime>() {
@Override
public OffsetDateTime apply(OffsetDateTime d, ZoneId z) {
return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime()));
}
});
public static final CustomInstantDeserializer<ZonedDateTime> ZONED_DATE_TIME = new CustomInstantDeserializer<ZonedDateTime>(
ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME,
new Function<TemporalAccessor, ZonedDateTime>() {
@Override
public ZonedDateTime apply(TemporalAccessor temporalAccessor) {
return ZonedDateTime.from(temporalAccessor);
}
},
new Function<FromIntegerArguments, ZonedDateTime>() {
@Override
public ZonedDateTime apply(FromIntegerArguments a) {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId);
}
},
new Function<FromDecimalArguments, ZonedDateTime>() {
@Override
public ZonedDateTime apply(FromDecimalArguments a) {
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId);
}
},
new BiFunction<ZonedDateTime, ZoneId, ZonedDateTime>() {
@Override
public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) {
return zonedDateTime.withZoneSameInstant(zoneId);
}
});
protected final Function<FromIntegerArguments, T> fromMilliseconds;
protected final Function<FromDecimalArguments, T> fromNanoseconds;
protected final Function<TemporalAccessor, T> parsedToValue;
protected final BiFunction<T, ZoneId, T> adjust;
protected CustomInstantDeserializer(Class<T> supportedType,
DateTimeFormatter parser,
Function<TemporalAccessor, T> parsedToValue,
Function<FromIntegerArguments, T> fromMilliseconds,
Function<FromDecimalArguments, T> fromNanoseconds,
BiFunction<T, ZoneId, T> adjust) {
super(supportedType, parser);
this.parsedToValue = parsedToValue;
this.fromMilliseconds = fromMilliseconds;
this.fromNanoseconds = fromNanoseconds;
this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
@Override
public T apply(T t, ZoneId zoneId) {
return t;
}
} : adjust;
}
@SuppressWarnings("unchecked")
protected CustomInstantDeserializer(CustomInstantDeserializer<T> base, DateTimeFormatter f) {
super((Class<T>) base.handledType(), f);
parsedToValue = base.parsedToValue;
fromMilliseconds = base.fromMilliseconds;
fromNanoseconds = base.fromNanoseconds;
adjust = base.adjust;
}
@Override
protected JsonDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
if (dtf == _formatter) {
return this;
}
return new CustomInstantDeserializer<T>(this, dtf);
}
@SuppressWarnings("deprecation")
@Override
public T deserialize(JsonParser parser, DeserializationContext context) throws IOException {
// NOTE: Timestamps contain no timezone info, and are always in configured TZ.
// Only
// string values have to be adjusted to the configured TZ.
switch (parser.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_FLOAT: {
BigDecimal value = parser.getDecimalValue();
long seconds = value.longValue();
int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds);
return fromNanoseconds.apply(new FromDecimalArguments(
seconds, nanoseconds, getZone(context)));
}
case JsonTokenId.ID_NUMBER_INT: {
long timestamp = parser.getLongValue();
if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) {
return this.fromNanoseconds.apply(new FromDecimalArguments(
timestamp, 0, this.getZone(context)));
}
return this.fromMilliseconds.apply(new FromIntegerArguments(
timestamp, this.getZone(context)));
}
case JsonTokenId.ID_STRING: {
String string = parser.getText().trim();
if (string.length() == 0) {
return null;
}
if (string.endsWith("+0000")) {
string = string.substring(0, string.length() - 5) + "Z";
}
T value;
try {
TemporalAccessor acc = _formatter.parse(string);
value = parsedToValue.apply(acc);
if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) {
return adjust.apply(value, this.getZone(context));
}
} catch (DateTimeException e) {
throw _peelDTE(e);
}
return value;
}
}
throw context.mappingException("Expected type float, integer, or string.");
}
private ZoneId getZone(DeserializationContext context) {
// Instants are always in UTC, so don't waste compute cycles
return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone());
}
private static class FromIntegerArguments {
public final long value;
public final ZoneId zoneId;
private FromIntegerArguments(long value, ZoneId zoneId) {
this.value = value;
this.zoneId = zoneId;
}
}
private static class FromDecimalArguments {
public final long integer;
public final int fraction;
public final ZoneId zoneId;
private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) {
this.integer = integer;
this.fraction = fraction;
this.zoneId = zoneId;
}
}
}
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