Skip to content

Commit

Permalink
๐Ÿš€ [Deploy] - Response DTO ๋ฐ˜ํ™˜ ํƒ€์ž… ์ˆ˜์ • (#42)
Browse files Browse the repository at this point in the history
* Feat: customException ๊ตฌํ˜„

* Feat: responseDto ๊ตฌํ˜„

* Feat: ๋‚ด ๊ทผ์ฒ˜ ํ‚ฅ๋ณด๋“œ ์ฃผ์ฐจ์žฅ ์ฐพ๊ธฐ API ๊ตฌํ˜„

* Fix: BoardingRecord ๋„๋ฉ”์ธ ์ˆ˜์ •

* Feat: Spring Security, JWT Cookie, ์†Œ์…œ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Feat: Spring Security, JWT Cookie, ์†Œ์…œ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Fix: ์ฝ”๋“œ ์—๋Ÿฌ ์ˆ˜์ •

* Refactor: ์•„์ง ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฝ”๋“œ ์‚ญ์ œ

* Feat: oauth2 ์˜์กด์„ฑ ์ถ”๊ฐ€

* Chore: Credentials ์ถ”๊ฐ€

* โœจ [Feature] - ์„œ๋ฒ„ ๋‚ ์งœ ์„ค์ • ๋ฐ ์œ ์ € ๋‹‰๋„ค์ž„ ์„ค์ • (#15)

* Feat: ์Šคํ”„๋ง ์„œ๋ฒ„ ์‹œ๊ฐ„ ํ•œ๊ตญ์œผ๋กœ ์„ค์ •

* Feat: ์‚ฌ์šฉ์ž ๋‹‰๋„ค์ž„ ์ง€์ • ๋กœ์ง ์ถ”๊ฐ€

* Fix: ์ดˆ๊ธฐ ํฌ์ธํŠธ ์„ค์ •

* Fix: nickname ์—๋Ÿฌ ์ˆ˜์ • (#18)

* Fix: BoardingRecord ๋„๋ฉ”์ธ ์ˆ˜์ •

* Feat: ๋””ํŽœ๋˜์‹œ ์ถ”๊ฐ€

* Feat: ErrorCode ์ถ”๊ฐ€

* Feat: Image API ๊ตฌํ˜„

* Feat: WebClientConfig ๊ตฌํ˜„

* Feat: S3ClientConfig ๊ตฌํ˜„

* Feat: BoardingRecord API ๊ตฌํ˜„

* Feat: ์ฃผ์ฐจ์žฅ ์˜ˆ์ธก ๊ฒฐ๊ณผ ๊ด€๋ จ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

* Feat: ํƒ‘์Šน ๊ธฐ๋ก ์ €์žฅ API ๊ตฌํ˜„

* Fix: ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ ์ˆ˜์ •

* Feat: ์ฝ”๋“œ ๋ฆฌํŒฉํ„ฐ๋ง ์ง„ํ–‰

* Chore: Credentials ์ˆ˜์ • (#29)

* !HOTFIX: ์„œ๋ธŒ ๋ชจ๋“ˆ ์ปจํ”Œ๋ฆญํŠธ ํ•ด๊ฒฐ

* โœจ [Feature] - Reissue ํ† ํฐ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ (#31)

* Chore: Credentials ์ˆ˜์ •

* Feat: Reissue ํ† ํฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„

* Chore: Credentials ์ถ”๊ฐ€

* Fix: JsonProperty ์ถ”๊ฐ€

* Fix: ResponseDto ํ•„๋“œ๋ณ€์ˆ˜ ์ด๋ฆ„ ์ˆ˜์ •

* Fix: ResponseDto ํ•„๋“œ๋ณ€์ˆ˜ ์ด๋ฆ„ ์ˆ˜์ • (#35)

* Feat: District ๋„๋ฉ”์ธ ์ƒ์„ฑ

* Feat: District ๋„๋ฉ”์ธ ์ปฌ๋Ÿผ ์ถ”๊ฐ€

* Feat: District API ๊ตฌํ˜„

* Feat: District API ๊ด€๋ จ DTO ๊ตฌํ˜„

* Feat: District API ๊ด€๋ จ DTO ๊ตฌํ˜„

* Feat: RestTemplateService ๊ตฌํ˜„

* Fix: ResponseDto ํ•„๋“œ๋ณ€์ˆ˜ ์ด๋ฆ„ ์ˆ˜์ • (#38)

* Feat: ์‹ค์‹œ๊ฐ„ ๋‚ ์”จ ํ™•์ธ DTO ๊ตฌํ˜„

* Feat: ์‹ค์‹œ๊ฐ„ ๋‚ ์”จ ํ™•์ธ API ๊ตฌํ˜„

* Fix: ๋ณ€์ˆ˜๋ช… ์ˆ˜์ •

* Fix: PointResponse ๋ฐ˜ํ™˜ ํƒ€์ž… ๋ณ€๊ฒฝ

* Fix: ๊ธฐ์ƒ์ฒญ API ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ catch ์ฝ”๋“œ ์ถ”๊ฐ€

---------

Co-authored-by: JeongHeumChoi <[email protected]>
Co-authored-by: JeongHeumChoi <[email protected]>
  • Loading branch information
3 people committed May 9, 2024
1 parent f0bb8b6 commit 57d3b70
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public record PointResponse(
Long point,

@JsonProperty("pm10")
Double pm10,
String pm10,

@JsonProperty("pm25")
Double pm25
String pm25
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

@Builder
public record DustResponse(
Double pm10,
String pm10,

Double pm25
String pm25
) {
}
110 changes: 75 additions & 35 deletions src/main/java/ice/spot/service/RestTemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import ice.spot.dto.district.response.weather.WeatherResultResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -38,9 +42,34 @@ public DustResponse getRealtimeCityAir(String territory, String district) {
.toUri();
DustResultResponse dustResultResponse = restTemplate.getForObject(uri, DustResultResponse.class);

Double pm10 = dustResultResponse.realtimeCityAirResponse().rowResponses().get(0).PM10();
String pm10grade = null;
Double pm25 = dustResultResponse.realtimeCityAirResponse().rowResponses().get(0).PM25();
String pm25grade = null;

if(pm10 > 0 && pm10 <= 30) {
pm10grade = "์ข‹์Œ";
} else if (pm10 > 30 && pm10 <= 80) {
pm10grade = "๋ณดํ†ต";
} else if (pm10 > 80 && pm10 <= 150) {
pm10grade = "๋‚˜์จ";
} else if (pm10 > 150) {
pm10grade = "๋งค์šฐ ๋‚˜์จ";
}

if(pm25 > 0 && pm25 <= 15) {
pm25grade = "์ข‹์Œ";
} else if (pm25 > 15 && pm25 <= 50) {
pm25grade = "๋ณดํ†ต";
} else if (pm25 > 50 && pm25 <= 100) {
pm25grade = "๋‚˜์จ";
} else if (pm25 > 100) {
pm25grade = "๋งค์šฐ ๋‚˜์จ";
}

DustResponse dustResponse = DustResponse.builder()
.pm10(dustResultResponse.realtimeCityAirResponse().rowResponses().get(0).PM10())
.pm25(dustResultResponse.realtimeCityAirResponse().rowResponses().get(0).PM25())
.pm10(pm10grade)
.pm25(pm25grade)
.build();

return dustResponse;
Expand All @@ -50,46 +79,57 @@ public DustResponse getRealtimeCityAir(String territory, String district) {
@Transactional
public TemperatureResponse getRealtimeWeather(String nx, String ny) {

final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
final HttpEntity<?> entity = new HttpEntity<>(headers);

LocalDateTime localDateTime = LocalDateTime.now().plusMinutes(-20);
LocalDateTime parsedLocalDateTime = LocalDateTime.parse(localDateTime.toString());
String yyyy = parsedLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy"));
String MM = parsedLocalDateTime.format(DateTimeFormatter.ofPattern("MM"));
String DD = parsedLocalDateTime.format(DateTimeFormatter.ofPattern("dd"));
String HH = parsedLocalDateTime.format(DateTimeFormatter.ofPattern("HH")) + "00";

URI uri = UriComponentsBuilder
.fromUriString("http://apis.data.go.kr")
.path("/1360000/VilageFcstInfoService_2.0/getUltraSrtNcst")
.queryParam("ServiceKey", "zNmiod%2F0aq5%2F06rrd8wHCmHhake9Vvj%2BY%2BX%2BsnrK7AU9uvTvg2qtAfZrjm9Gu1navvJG3%2B9sSN6MfriPi0rlLA%3D%3D")
.queryParam("pageNo", "1")
.queryParam("numOfRows", "10")
.queryParam("dataType", "JSON")
.queryParam("base_date", yyyy+MM+DD)
.queryParam("base_time", HH)
.queryParam("nx", nx)
.queryParam("ny", ny)
.encode()
.build()
.toUri();

WeatherResultResponse weatherResultResponse = restTemplate.getForObject(uri, WeatherResultResponse.class);
List<WeatherItemResponse> weatherItemResponses = weatherResultResponse.realtimeWeatherResponse()
.weatherBody()
.weatherItemListResponse()
.weatherItemResponses();

String T1H = null;
String REH = null;
for(WeatherItemResponse weatherItemResponse : weatherItemResponses) {
if(weatherItemResponse.category().equals("T1H")) T1H = weatherItemResponse.obsrValue();
if(weatherItemResponse.category().equals("REH")) REH = weatherItemResponse.obsrValue();
try {
URI uri = UriComponentsBuilder
.fromUriString("http://apis.data.go.kr")
.path("/1360000/VilageFcstInfoService_2.0/getUltraSrtNcst")
.queryParam("ServiceKey", "zNmiod/0aq5/06rrd8wHCmHhake9Vvj+Y+X+snrK7AU9uvTvg2qtAfZrjm9Gu1navvJG3+9sSN6MfriPi0rlLA==")
.queryParam("pageNo", "1")
.queryParam("numOfRows", "10")
.queryParam("dataType", "JSON")
.queryParam("base_date", yyyy+MM+DD)
.queryParam("base_time", HH)
.queryParam("nx", nx)
.queryParam("ny", ny)
.encode()
.build()
.toUri();
WeatherResultResponse weatherResultResponse = restTemplate.exchange(uri, HttpMethod.GET, entity, WeatherResultResponse.class).getBody();

List<WeatherItemResponse> weatherItemResponses = weatherResultResponse.realtimeWeatherResponse()
.weatherBody()
.weatherItemListResponse()
.weatherItemResponses();

String T1H = null;
String REH = null;
for(WeatherItemResponse weatherItemResponse : weatherItemResponses) {
if(weatherItemResponse.category().equals("T1H")) T1H = weatherItemResponse.obsrValue();
if(weatherItemResponse.category().equals("REH")) REH = weatherItemResponse.obsrValue();
}

TemperatureResponse temperatureResponse = TemperatureResponse.builder()
.temperature(Double.parseDouble(T1H))
.humidity(Double.parseDouble(REH))
.build();

return temperatureResponse;
} catch (Exception e) {
return TemperatureResponse.builder()
.temperature(14.0)
.humidity(79.0)
.build();
}

TemperatureResponse temperatureResponse = TemperatureResponse.builder()
.temperature(Double.parseDouble(T1H))
.humidity(Double.parseDouble(REH))
.build();

return temperatureResponse;
}
}

0 comments on commit 57d3b70

Please sign in to comment.