HistoricalweatherApiController.java 4.68 KB
Newer Older
EnesKarakas's avatar
EnesKarakas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
    }

}