Skip to content

Commit

Permalink
fix: main api 예외처리 변경 (#22)
Browse files Browse the repository at this point in the history
fix: main api 예외처리 변경 (#22)
  • Loading branch information
jinho7 authored Sep 27, 2024
2 parents d07667f + 2c6c62a commit fa267d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 124 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ public MainWeatherResponse getMainWeather(double latitude, double longitude) {

String expectedWeatherKey = regionName + "_" + convertLocalDateTimeToString(now);

LocalDateTime dailyWeatherBaseTime = convertLocalDateTimeToDailyWeatherTime(now.minusHours(1));
String dailyWeatherKey = regionName + "_" + convertLocalDateTimeToString(dailyWeatherBaseTime);
LocalDateTime dailyWeatherBaseTime = convertLocalDateTimeToDailyWeatherTime(now);
String dailyWeatherKey = regionName + "_" + convertLocalDateTimeToString(dailyWeatherBaseTime.plusHours(1));

log.info("[Main - api] dailyWeatherKey : {}", dailyWeatherKey);
log.info("[Main - api] expectedWeatherKey : {}", expectedWeatherKey);

DailyWeather dailyWeather = dailyWeatherRepository.findById(dailyWeatherKey)
.orElseGet(() -> {
log.info("[Main - api] Daily Weather Error");
try {
String[] baseTime = convertLocalDateTimeToString(now.minusHours(2)).split("_");
LocalDateTime dailyTime = convertLocalDateTimeToDailyWeatherTime(now);
String[] baseTime = convertLocalDateTimeToString(dailyTime).split("_");
createDailyWeather(region.getStartX(), region.getStartY(), baseTime[0], baseTime[1]);
} catch (URISyntaxException e) {
throw new CustomException(WeatherErrorCode.WEATHER_URI_ERROR);
Expand All @@ -191,6 +193,7 @@ public MainWeatherResponse getMainWeather(double latitude, double longitude) {

ExpectedWeather expectedWeather = expectedWeatherRepository.findById(expectedWeatherKey)
.orElseGet(() -> {
log.info("[Main - api] Expected Weather Error");
try {
String[] baseTime = convertLocalDateTimeToString(now.minusHours(1)).split("_");
createExpectedWeather(region.getStartX(), region.getStartY(), baseTime[0], baseTime[1]);
Expand Down Expand Up @@ -232,13 +235,13 @@ public String convertLocalDateTimeToString(LocalDateTime time) {
public LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) {

// DailyWeather 정보는 3시간마다
List<Integer> scheduledHours = Arrays.asList(0, 3, 6, 9, 12, 15, 18, 21);
List<Integer> scheduledHours = Arrays.asList(2, 5, 8, 11, 14, 17, 20, 23);

int currentHour = time.getHour();
int adjustedHour = scheduledHours.stream()
.filter(hour -> hour <= currentHour)
.reduce((first, second) -> second)
.orElse(scheduledHours.get(scheduledHours.size() - 1)); // 이전 날의 마지막 스케줄 시간(21시) 반환
.orElse(scheduledHours.get(scheduledHours.size() - 1));

// 현재 시간이 첫 스케줄 시간(0시)보다 작을 경우, 전날의 마지막 스케줄 시간으로 설정
if (currentHour < scheduledHours.get(0)) {
Expand Down
61 changes: 0 additions & 61 deletions src/main/resources/application.yml

This file was deleted.

0 comments on commit fa267d8

Please sign in to comment.