Skip to content

Commit 3631260

Browse files
committed
[feat] 추천활동이 여러개 일 시 모두 반환해주기 위해 응답값을 리스트로 변경
1 parent 2a6633b commit 3631260

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/main/java/nambang_swag/bada_on/response/WeatherSummary.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22

33
import java.util.List;
44

5-
import nambang_swag.bada_on.constant.Activity;
65
import nambang_swag.bada_on.entity.Weather;
76

87
public record WeatherSummary(
98
int date,
109
int hour,
1110
List<String> warning,
12-
String recommendActivity,
11+
List<String> recommendActivity,
1312
String skyCondition,
1413
float temperature,
1514
String wind,
1615
float tideHeight,
1716
float waveHeight
1817
) {
19-
public static WeatherSummary of(Weather weather, List<String> warning, Activity recommendActivity,
18+
public static WeatherSummary of(Weather weather, List<String> warning, List<String> recommendActivities,
2019
float tideHeight) {
2120
return new WeatherSummary(
2221
weather.getDate(),
2322
weather.getTime() / 100,
2423
warning,
25-
recommendActivity.getValue(),
24+
recommendActivities,
2625
getSkyCondition(weather),
2726
weather.getHourlyTemperature(),
2827
getWindString(weather.getWindSpeed()),

src/main/java/nambang_swag/bada_on/service/WeatherService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.time.format.DateTimeFormatter;
77
import java.time.temporal.ChronoUnit;
88
import java.util.ArrayList;
9+
import java.util.Collections;
910
import java.util.Comparator;
1011
import java.util.HashMap;
1112
import java.util.List;
@@ -61,7 +62,7 @@ public WeatherSummary getWeatherSummary(Long id, int date, int hour) {
6162
return WeatherSummary.of(
6263
weather,
6364
new ArrayList<>(),
64-
getRecommendActivity(weather, tideRecords),
65+
getRecommendActivities(weather, tideRecords),
6566
tidePercentage
6667
);
6768
}
@@ -100,7 +101,7 @@ public WeatherDetail getWeatherDetail(Long placeId, int date, int hour) {
100101
);
101102
}
102103

103-
private Activity getRecommendActivity(Weather weather, List<TideRecord> tideRecords) {
104+
private List<String> getRecommendActivities(Weather weather, List<TideRecord> tideRecords) {
104105
Map<Activity, Integer> activityScores = new HashMap<>();
105106

106107
activityScores.put(SNORKELING, calculateSnorkelingScore(weather, tideRecords));
@@ -109,10 +110,12 @@ private Activity getRecommendActivity(Weather weather, List<TideRecord> tideReco
109110
activityScores.put(KAYAKING_AND_PADDLE_BOARDING, calculateKayakingPaddleBoardingScore(weather, tideRecords));
110111
activityScores.put(SURFING, calculateSurfingScore(weather, tideRecords));
111112

113+
int maxScore = Collections.max(activityScores.values());
114+
112115
return activityScores.entrySet().stream()
113-
.max(Map.Entry.comparingByValue())
114-
.orElseThrow(() -> new IllegalStateException("No activity scores available"))
115-
.getKey();
116+
.filter(entry -> entry.getValue() == maxScore)
117+
.map(entry -> entry.getKey().getValue())
118+
.collect(Collectors.toList());
116119
}
117120

118121
// Calculate Point

0 commit comments

Comments
 (0)