Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #66

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@Configuration
class DataGoConfig {
class DataAPIConfig {

@Bean
public DataGoAPI dataGoApi() {
public DataGoAPI dataGoAPI() {
WebClient client = WebClient.create("https://apis.data.go.kr");

return HttpServiceProxyFactory
Expand All @@ -19,4 +19,14 @@ public DataGoAPI dataGoApi() {
.createClient(DataGoAPI.class);
}

@Bean
public DataSeoulAPI DataSeoulAPI() {
WebClient client = WebClient.create("http://openapi.seoul.go.kr:8088");

return HttpServiceProxyFactory
.builderFor(WebClientAdapter.create(client))
.build()
.createClient(DataSeoulAPI.class);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.seoultech.sanEseo.global.config;

import com.seoultech.sanEseo.weather.application.service.WeatherAPIResponse;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.service.annotation.GetExchange;

public interface DataGoAPI {

@GetExchange("/1360000/VilageFcstInfoService_2.0/getVilageFcst?serviceKey={serviceKey}&pageNo=1&numOfRows=20&dataType=json&base_date={base_date}&base_time={base_time}&nx={nx}&ny={ny}")
String getWeather(
@GetExchange("/1360000/VilageFcstInfoService_2.0/getVilageFcst?serviceKey={serviceKey}&pageNo=1&numOfRows=1000&dataType=json&base_date={base_date}&base_time={base_time}&nx={nx}&ny={ny}")
WeatherAPIResponse getWeather(
@PathVariable("serviceKey") String serviceKey,
@PathVariable("base_date") String baseDate,
@PathVariable("base_time") String baseTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.seoultech.sanEseo.global.config;

import com.seoultech.sanEseo.weather.application.service.PollutionAPIResponse;
import com.seoultech.sanEseo.weather.application.service.WeatherAPIResponse;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.service.annotation.GetExchange;

public interface DataSeoulAPI {

@GetExchange("/{serviceKey}/json/ListAirQualityByDistrictService/1/1/{code}/")
PollutionAPIResponse getPollution(
@PathVariable("serviceKey") String serviceKey,
@PathVariable("code") int code
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WeatherController {
private final WeatherService weatherService;
@GetMapping
public ResponseEntity<?> getWeather(@RequestParam Long districtId) {
return ApiResponse.ok("기상 정보 조회 성공", weatherService.getWeatherData(districtId));
return ApiResponse.ok("기상 정보 조회 성공", weatherService.getWeatherResponse(districtId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class WeatherResponse {
private Float temperature;
private Float temperatureMax;
private Float temperatureMin;
private int precipitation;
private String precipitation;
private int humidity;
private Float microDust;
private Float ultraMicroDust;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.seoultech.sanEseo.weather.application.service;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.List;

@Data
public class PollutionAPIResponse {

@JsonProperty("ListAirQualityByDistrictService")
private ListAirQualityByDistrictService listAirQualityByDistrictService;

@Data
public static class ListAirQualityByDistrictService {
@JsonProperty("list_total_count")
private int count;

private List<AirQualityData> row;
}

@Data
public static class AirQualityData {
@JsonProperty("MSRDATE")
private String date;
@JsonProperty("MSRADMCODE")
private String districtCode;
@JsonProperty("MSRSTENAME")
private String districtName;
@JsonProperty("MAXINDEX")
private String maxIndex;
@JsonProperty("GRADE")
private String grade;
@JsonProperty("POLLUTANT")
private String pollutant;
@JsonProperty("NITROGEN")
private String nitrogen;
@JsonProperty("OZONE")
private String ozone;
@JsonProperty("CARBON")
private String carbon;
@JsonProperty("SULFUROUS")
private String sulfurous;
@JsonProperty("PM10")
private String pm10;
@JsonProperty("PM25")
private String pm25;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.seoultech.sanEseo.weather.application.service;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;

@Data
public class WeatherAPIResponse {
@JsonProperty("response")
private Response response;

@Data
public static class Response {
private Header header;
private Body body;
}

@Data
public static class Header {
private String resultCode;
private String resultMsg;
}

@Data
public static class Body {
private String dataType;
private Items items;
private int pageNo;
private int numOfRows;
private int totalCount;
}

@Data
public static class Items {
private List<Item> item;
}

@Data
public static class Item {
private String baseDate;
private String baseTime;
private String category;
private String fcstDate;
private String fcstTime;
private String fcstValue;
private int nx;
private int ny;
}

public String getValueByCategoryAndDateTime(String category, String fcstDate, String fcstTime) {
for (Item item : response.body.items.item) {
if (item.getCategory().equals(category) && item.getFcstDate().equals(fcstDate) && item.getFcstTime().equals(fcstTime)) {
return item.getFcstValue();
}
}
return null;
}

public String getValueByCategoryAndDate(String category, String fcstDate) {
for (Item item : response.body.items.item) {
if (item.getCategory().equals(category) && item.getFcstDate().equals(fcstDate)) {
return item.getFcstValue();
}
}
return null;
}
}
Loading