Skip to content

Commit fc50f41

Browse files
authored
Merge d1a3117 into dc300f2
2 parents dc300f2 + d1a3117 commit fc50f41

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

src/main/java/sevenstar/marineleisure/activity/dto/request/ActivityWeatherRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.math.BigDecimal;
44

55
public record ActivityWeatherRequest(
6-
BigDecimal latitude,
7-
BigDecimal longitude
6+
Float latitude,
7+
Float longitude
88
) {
99
}

src/main/java/sevenstar/marineleisure/activity/service/ActivityService.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9+
import java.util.NoSuchElementException;
910
import java.util.Optional;
1011

1112
import org.springframework.stereotype.Service;
@@ -26,6 +27,7 @@
2627
import sevenstar.marineleisure.forecast.repository.ScubaRepository;
2728
import sevenstar.marineleisure.forecast.repository.SurfingRepository;
2829
import sevenstar.marineleisure.global.enums.ActivityCategory;
30+
import sevenstar.marineleisure.global.enums.TimePeriod;
2931
import sevenstar.marineleisure.spot.domain.OutdoorSpot;
3032
import sevenstar.marineleisure.spot.repository.OutdoorSpotRepository;
3133

@@ -205,34 +207,22 @@ public ActivityDetailResponse getActivityDetail(ActivityCategory activity, BigDe
205207
}
206208

207209
@Transactional(readOnly = true)
208-
public ActivityWeatherResponse getWeatherBySpot(BigDecimal latitude, BigDecimal longitude) {
209-
OutdoorSpot nearSpot = outdoorSpotRepository.findByCoordinates(latitude, longitude, 1).getFirst();
210-
211-
Optional<Fishing> fishingSpot = fishingRepository.findBySpotIdOrderByCreatedAt(nearSpot.getId());
212-
213-
if (fishingSpot.isPresent()) {
214-
Fishing fishingSpotGet = fishingSpot.get();
215-
216-
return new ActivityWeatherResponse(
217-
nearSpot.getName(),
218-
fishingSpotGet.getWindSpeedMax().toString(),
219-
fishingSpotGet.getWaveHeightMax().toString(),
220-
fishingSpotGet.getSeaTempMax().toString()
221-
);
222-
}
223-
224-
Optional<Surfing> surfingSpot = surfingRepository.findBySpotIdOrderByCreatedAt(nearSpot.getId());
225-
226-
if (surfingSpot.isPresent()) {
227-
Surfing surfingSpotGet = surfingSpot.get();
228-
return new ActivityWeatherResponse(
229-
nearSpot.getName(),
230-
surfingSpotGet.getWindSpeed().toString(),
231-
surfingSpotGet.getWaveHeight().toString(),
232-
surfingSpotGet.getSeaTemp().toString()
233-
);
234-
} else {
235-
throw new RuntimeException("Spot not found");
236-
}
210+
public ActivityWeatherResponse getWeatherBySpot(Float latitude, Float longitude) {
211+
// 1. 가까운 낚시 지점 조회
212+
OutdoorSpot nearSpot = outdoorSpotRepository.findNearFishingSpot(latitude.doubleValue(),longitude.doubleValue())
213+
.orElseThrow(() -> new NoSuchElementException("가까운 낚시 지점을 찾을 수 없습니다."));
214+
215+
// 2. 해당 지점의 예보 데이터 조회
216+
Fishing fishing = fishingRepository.findFishingBySpotIdAndForecastDateAndTimePeriod(nearSpot.getId(), LocalDate.now(),
217+
TimePeriod.AM)
218+
.orElseThrow(() -> new NoSuchElementException("해당 지점에 대한 예보 정보를 찾을 수 없습니다."));
219+
220+
// 3. 결과 조합
221+
return new ActivityWeatherResponse(
222+
nearSpot.getName(),
223+
fishing.getWindSpeedMax().toString(),
224+
fishing.getWaveHeightMax().toString(),
225+
fishing.getSeaTempMax().toString()
226+
);
237227
}
238228
}

src/main/java/sevenstar/marineleisure/forecast/repository/FishingRepository.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import jakarta.transaction.Transactional;
1313
import sevenstar.marineleisure.forecast.domain.Fishing;
14+
import sevenstar.marineleisure.global.enums.TimePeriod;
1415
import sevenstar.marineleisure.spot.dto.projection.FishingReadProjection;
1516
import sevenstar.marineleisure.spot.repository.ActivityRepository;
1617

@@ -117,9 +118,13 @@ Optional<Fishing> findFirstBySpotIdAndCreatedAtGreaterThanEqualAndCreatedAtLessT
117118
LocalDateTime endDateTime
118119
);
119120

120-
Optional<Fishing> findTopByCreatedAtGreaterThanEqualAndCreatedAtLessThanOrderByTotalIndexDesc(LocalDateTime start, LocalDateTime end);
121+
Optional<Fishing> findTopByCreatedAtGreaterThanEqualAndCreatedAtLessThanOrderByTotalIndexDesc(LocalDateTime start,
122+
LocalDateTime end);
121123

122124
Optional<Fishing> findBySpotIdAndCreatedAtBeforeOrderByCreatedAtDesc(Long spotId, LocalDateTime createdAtBefore);
123125

124126
Optional<Fishing> findBySpotIdOrderByCreatedAt(Long spotId);
127+
128+
Optional<Fishing> findFishingBySpotIdAndForecastDateAndTimePeriod(Long spotId, LocalDate forecastDate,
129+
TimePeriod timePeriod);
125130
}

src/main/java/sevenstar/marineleisure/spot/repository/OutdoorSpotRepository.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,13 @@ Optional<BestSpotProjection> findBestSpotInScuba(@Param("latitude") double latit
177177
""", nativeQuery = true)
178178
List<OutdoorSpot> findByCoordinates(@Param("latitude") BigDecimal latitude,
179179
@Param("longitude") BigDecimal longitude, @Param("limit") int limit);
180+
181+
@Query(value = """
182+
SELECT * FROM outdoor_spots os
183+
WHERE os.category = 'FISHING'
184+
ORDER BY ST_Distance_Sphere(os.geo_point, ST_SRID(POINT(:longitude, :latitude), 4326)) ASC
185+
LIMIT 1;
186+
""",nativeQuery = true)
187+
Optional<OutdoorSpot> findNearFishingSpot(@Param("latitude") double latitude,
188+
@Param("longitude") double longitude);
180189
}

0 commit comments

Comments
 (0)