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

Feat: weather 조회 api 추가 #117

Merged
merged 1 commit into from
Aug 31, 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
@@ -0,0 +1,24 @@
package com.dnd.runus.application.weather;

import com.dnd.runus.infrastructure.weather.WeatherClient;
import com.dnd.runus.infrastructure.weather.WeatherInfo;
import com.dnd.runus.presentation.v1.weather.dto.WeatherResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class WeatherService {
private final WeatherClient weatherClient;

public WeatherResponse getWeather(double longitude, double latitude) {
WeatherInfo info = weatherClient.getWeatherInfo(longitude, latitude);
return new WeatherResponse(
info.weatherType().getKoreanName(),
info.weatherType().getKoreanDescription(),
info.weatherType().getIconUrl(),
(int) info.apparentTemperature(),
(int) info.minTemperature(),
(int) info.maxTemperature());
}
}
29 changes: 20 additions & 9 deletions src/main/java/com/dnd/runus/global/constant/WeatherType.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.dnd.runus.global.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import static lombok.AccessLevel.PACKAGE;

@Getter
@RequiredArgsConstructor(access = PACKAGE)
public enum WeatherType {
CLEAR,
CLOUDY,
CLOUDY_MORE,
RAIN,
SNOW,
FOG,
STORM,
HEAT_WAVE,
COLD_WAVE
CLEAR("맑음", "해가 쨍쨍하니 러닝하면 어떨까요?", "https://d27big3ufowabi.cloudfront.net/weather/A1.png"),
CLOUDY("구름 조금", "구름이 조금 있는 날씨입니다", "https://d27big3ufowabi.cloudfront.net/weather/A2.png"),
CLOUDY_MORE("흐림", "구름이 많은 날씨입니다", "https://d27big3ufowabi.cloudfront.net/weather/A3.png"),
RAIN("비내리는 날", "빗물이 고인 곳이 많을 수 있으니 달리며 미끄러지지 않도록 조심하세요", "https://d27big3ufowabi.cloudfront.net/weather/A4.png"),
SNOW("눈", "눈길에 미끄러지지 않도록 조심하세요", "https://d27big3ufowabi.cloudfront.net/weather/B1.png"),
FOG("안개", "안개가 짙으니 시야확보에 유의하세요", "https://d27big3ufowabi.cloudfront.net/weather/B2.png"),
STORM("폭풍", "폭풍이 몰아치는 날씨입니다. 외부 활동을 삼가하세요", "https://d27big3ufowabi.cloudfront.net/weather/B3.png"),
HEAT_WAVE("폭염", "기온이 매우 높으니 충분한 수분 섭취에 유의하세요", "https://d27big3ufowabi.cloudfront.net/weather/C1.png"),
COLD_WAVE("한파", "기온이 매우 낮으니 러닝 전 따뜻하게 준비하세요", "https://d27big3ufowabi.cloudfront.net/weather/C2.png"),
;
private final String koreanName;
private final String koreanDescription;
private final String iconUrl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.dnd.runus.presentation.v1.weather;

import com.dnd.runus.application.weather.WeatherService;
import com.dnd.runus.presentation.v1.weather.dto.WeatherResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1/weathers")
public class WeatherController {
private final WeatherService weatherService;

@GetMapping
@ResponseStatus(HttpStatus.OK)
public WeatherResponse getWeather(double longitude, double latitude) {
return weatherService.getWeather(longitude, latitude);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dnd.runus.presentation.v1.weather.dto;

import io.swagger.v3.oas.annotations.media.Schema;

public record WeatherResponse(
@Schema(description = "날씨 이름", example = "맑음")
String weatherName,
@Schema(description = "날씨 안내 문구", example = "해가 쨍쨍한 날씨입니다.")
String weatherDescription,
@Schema(description = "날씨 아이콘 URL", format = "uri")
String weatherIconUrl,
@Schema(description = "체감온도 (°C)", example = "23")
int apparentTemperature,
@Schema(description = "최저기온 (°C)", example = "20")
int minTemperature,
@Schema(description = "최고기온 (°C)", example = "25")
int maxTemperature
) {
}