Skip to content

Commit 0c1a69c

Browse files
JIWONKIMSclaude
andauthored
feat(be) : work 4 (#16) (#19)
* feat(be) : weather commit * feat(be) : weather commit2 * feat(be): weather 관련 코드 수정 및 ktlint 포맷팅 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * feat(be): 파일명 규칙에 맞게 수정 및 ktlint 적용 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 9b4d06c commit 0c1a69c

File tree

4 files changed

+76
-26
lines changed

4 files changed

+76
-26
lines changed

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/weather/client/WeatherApiClient.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class WeatherApiClient(
7272
fun fetchLandForecast(
7373
regionId: String,
7474
baseTime: String,
75-
): PrecipitationData? {
75+
): LandForecastData? {
7676
val url = "$apiUrl/getMidLandFcst?serviceKey=$serviceKey&numOfRows=10&pageNo=1&regId=$regionId&tmFc=$baseTime&dataType=JSON"
7777

7878
println("🌧️ 중기육상예보조회 API 호출: $url")
@@ -82,10 +82,10 @@ class WeatherApiClient(
8282
val jsonResponse = restTemplate.getForObject(url, Map::class.java) as? Map<String, Any>
8383
println("📡 중기육상예보 JSON 응답 수신")
8484

85-
jsonResponse?.let { dataParser.parsePrecipitationDataFromJson(it) } ?: PrecipitationData()
85+
jsonResponse?.let { dataParser.parsePrecipitationDataFromJson(it) } ?: LandForecastData()
8686
} catch (e: Exception) {
8787
println("❌ 중기육상예보조회 JSON API 오류: ${e.message}")
88-
PrecipitationData()
88+
LandForecastData()
8989
}
9090
}
9191
}

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/weather/client/parser/DataParser.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.back.koreaTravelGuide.domain.ai.weather.client.parser
22

3+
import com.back.koreaTravelGuide.domain.ai.weather.dto.LandForecastData
4+
import com.back.koreaTravelGuide.domain.ai.weather.dto.LandForecastInfo
35
import com.back.koreaTravelGuide.domain.ai.weather.dto.TemperatureData
46
import com.back.koreaTravelGuide.domain.ai.weather.dto.TemperatureInfo
57
import org.springframework.stereotype.Component
@@ -36,7 +38,7 @@ class DataParser {
3638

3739
// 기온 데이터 JSON 파싱
3840
fun parseTemperatureDataFromJson(jsonResponse: Map<String, Any>): TemperatureData {
39-
val TemperatureData = TemperatureData()
41+
val temperatureData = TemperatureData()
4042

4143
for (day in 4..10) {
4244
val minTemp = (extractJsonValue(jsonResponse, "response.body.items.item[0].taMin$day") as? Number)?.toInt()
@@ -55,16 +57,16 @@ class DataParser {
5557
maxTempRange = if (maxTempLow != null && maxTempHigh != null) "$maxTempLow~$maxTempHigh" else null,
5658
)
5759

58-
TemperatureData.setDay(day, tempInfo)
60+
temperatureData.setDay(day, tempInfo)
5961
}
6062
}
6163

62-
return TemperatureData
64+
return temperatureData
6365
}
6466

6567
// 강수 확률 데이터 JSON 파싱
66-
fun parsePrecipitationDataFromJson(jsonResponse: Map<String, Any>): PrecipitationData {
67-
val precipitationData = PrecipitationData()
68+
fun parsePrecipitationDataFromJson(jsonResponse: Map<String, Any>): LandForecastData {
69+
val landForecastData = LandForecastData()
6870

6971
for (day in 4..10) {
7072
if (day <= 7) {
@@ -76,14 +78,14 @@ class DataParser {
7678

7779
if (amRain != null || pmRain != null || !amWeather.isNullOrBlank() || !pmWeather.isNullOrBlank()) {
7880
val precipInfo =
79-
PrecipitationInfo(
81+
LandForecastInfo(
8082
amRainPercent = amRain,
8183
pmRainPercent = pmRain,
8284
amWeather = amWeather,
8385
pmWeather = pmWeather,
8486
)
8587

86-
precipitationData.setDay(day, precipInfo)
88+
landForecastData.setDay(day, precipInfo)
8789
}
8890
} else {
8991
// 8~10일: 통합 (오전/오후 구분 없음)
@@ -92,18 +94,18 @@ class DataParser {
9294

9395
if (rainPercent != null || !weather.isNullOrBlank()) {
9496
val precipInfo =
95-
PrecipitationInfo(
97+
LandForecastInfo(
9698
amRainPercent = rainPercent,
9799
pmRainPercent = null,
98100
amWeather = weather,
99101
pmWeather = null,
100102
)
101103

102-
precipitationData.setDay(day, precipInfo)
104+
landForecastData.setDay(day, precipInfo)
103105
}
104106
}
105107
}
106108

107-
return precipitationData
109+
return landForecastData
108110
}
109111
}
Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
11
package com.back.koreaTravelGuide.domain.ai.weather.dto
22

3-
data class LandForecastData()
3+
@Suppress("unused") // JSON 직렬화를 위해 필요
4+
class LandForecastData(
5+
private val days: MutableMap<Int, LandForecastInfo?> = mutableMapOf(),
6+
) {
7+
fun setDay(
8+
day: Int,
9+
info: LandForecastInfo?,
10+
) {
11+
days[day] = info
12+
}
13+
14+
fun getDay(day: Int): LandForecastInfo? = days[day]
15+
16+
var day4: LandForecastInfo? get() = days[4]
17+
set(value) {
18+
days[4] = value
19+
}
20+
var day5: LandForecastInfo? get() = days[5]
21+
set(value) {
22+
days[5] = value
23+
}
24+
var day6: LandForecastInfo? get() = days[6]
25+
set(value) {
26+
days[6] = value
27+
}
28+
var day7: LandForecastInfo? get() = days[7]
29+
set(value) {
30+
days[7] = value
31+
}
32+
var day8: LandForecastInfo? get() = days[8]
33+
set(value) {
34+
days[8] = value
35+
}
36+
var day9: LandForecastInfo? get() = days[9]
37+
set(value) {
38+
days[9] = value
39+
}
40+
var day10: LandForecastInfo? get() = days[10]
41+
set(value) {
42+
days[10] = value
43+
}
44+
}
45+
46+
data class LandForecastInfo(
47+
val amRainPercent: Int?,
48+
val pmRainPercent: Int?,
49+
val amWeather: String?,
50+
val pmWeather: String?,
51+
)

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/weather/dto/TemperatureData.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
package com.back.koreaTravelGuide.domain.ai.weather.dto
22

3-
import kotlin.text.set
4-
53
// TODO: 날씨 내부 데이터 구조 - 기상청 API 응답 데이터 매핑용 내부 클래스들
64
@Suppress("unused") // JSON 직렬화를 위해 필요
7-
data class TemperatureData(
5+
class TemperatureData(
86
private val days: MutableMap<Int, TemperatureInfo?> = mutableMapOf(),
97
) {
108
fun setDay(
119
day: Int,
1210
info: TemperatureInfo?,
1311
) {
14-
days[day] set info
12+
days[day] = info
1513
}
1614

1715
fun getDay(day: Int): TemperatureInfo? = days[day]
1816

19-
var day4: TemperatureInfo? get() = days[4]
17+
var day4: TemperatureInfo?
18+
get() = days[4]
2019
set(value) {
21-
days[4] set value
20+
days[4] = value
2221
}
22+
2323
var day5: TemperatureInfo? get() = days[5]
2424
set(value) {
25-
days[5] set value
25+
days[5] = value
2626
}
2727
var day6: TemperatureInfo? get() = days[6]
2828
set(value) {
29-
days[6] set value
29+
days[6] = value
3030
}
3131
var day7: TemperatureInfo? get() = days[7]
3232
set(value) {
33-
days[7] set value
33+
days[7] = value
3434
}
3535
var day8: TemperatureInfo? get() = days[8]
3636
set(value) {
37-
days[8] set value
37+
days[8] = value
3838
}
3939
var day9: TemperatureInfo? get() = days[9]
4040
set(value) {
41-
days[9] set value
41+
days[9] = value
4242
}
4343
var day10: TemperatureInfo? get() = days[10]
4444
set(value) {
45-
days[10] set value
45+
days[10] = value
4646
}
4747
}
4848

0 commit comments

Comments
 (0)