Skip to content
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
Expand Up @@ -3,7 +3,7 @@
import java.math.BigDecimal;

public record ActivityWeatherRequest(
BigDecimal latitude,
BigDecimal longitude
Float latitude,
Float longitude
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;

import org.springframework.stereotype.Service;
Expand All @@ -26,6 +27,7 @@
import sevenstar.marineleisure.forecast.repository.ScubaRepository;
import sevenstar.marineleisure.forecast.repository.SurfingRepository;
import sevenstar.marineleisure.global.enums.ActivityCategory;
import sevenstar.marineleisure.global.enums.TimePeriod;
import sevenstar.marineleisure.spot.domain.OutdoorSpot;
import sevenstar.marineleisure.spot.repository.OutdoorSpotRepository;

Expand Down Expand Up @@ -205,34 +207,22 @@ public ActivityDetailResponse getActivityDetail(ActivityCategory activity, BigDe
}

@Transactional(readOnly = true)
public ActivityWeatherResponse getWeatherBySpot(BigDecimal latitude, BigDecimal longitude) {
OutdoorSpot nearSpot = outdoorSpotRepository.findByCoordinates(latitude, longitude, 1).getFirst();

Optional<Fishing> fishingSpot = fishingRepository.findBySpotIdOrderByCreatedAt(nearSpot.getId());

if (fishingSpot.isPresent()) {
Fishing fishingSpotGet = fishingSpot.get();

return new ActivityWeatherResponse(
nearSpot.getName(),
fishingSpotGet.getWindSpeedMax().toString(),
fishingSpotGet.getWaveHeightMax().toString(),
fishingSpotGet.getSeaTempMax().toString()
);
}

Optional<Surfing> surfingSpot = surfingRepository.findBySpotIdOrderByCreatedAt(nearSpot.getId());

if (surfingSpot.isPresent()) {
Surfing surfingSpotGet = surfingSpot.get();
return new ActivityWeatherResponse(
nearSpot.getName(),
surfingSpotGet.getWindSpeed().toString(),
surfingSpotGet.getWaveHeight().toString(),
surfingSpotGet.getSeaTemp().toString()
);
} else {
throw new RuntimeException("Spot not found");
}
public ActivityWeatherResponse getWeatherBySpot(Float latitude, Float longitude) {
// 1. 가까운 낚시 지점 조회
OutdoorSpot nearSpot = outdoorSpotRepository.findNearFishingSpot(latitude.doubleValue(),longitude.doubleValue())
.orElseThrow(() -> new NoSuchElementException("가까운 낚시 지점을 찾을 수 없습니다."));

// 2. 해당 지점의 예보 데이터 조회
Fishing fishing = fishingRepository.findFishingBySpotIdAndForecastDateAndTimePeriod(nearSpot.getId(), LocalDate.now(),
TimePeriod.AM)
.orElseThrow(() -> new NoSuchElementException("해당 지점에 대한 예보 정보를 찾을 수 없습니다."));

// 3. 결과 조합
return new ActivityWeatherResponse(
nearSpot.getName(),
fishing.getWindSpeedMax().toString(),
fishing.getWaveHeightMax().toString(),
fishing.getSeaTempMax().toString()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import jakarta.transaction.Transactional;
import sevenstar.marineleisure.forecast.domain.Fishing;
import sevenstar.marineleisure.global.enums.TimePeriod;
import sevenstar.marineleisure.spot.dto.projection.FishingReadProjection;
import sevenstar.marineleisure.spot.repository.ActivityRepository;

Expand Down Expand Up @@ -117,9 +118,13 @@ Optional<Fishing> findFirstBySpotIdAndCreatedAtGreaterThanEqualAndCreatedAtLessT
LocalDateTime endDateTime
);

Optional<Fishing> findTopByCreatedAtGreaterThanEqualAndCreatedAtLessThanOrderByTotalIndexDesc(LocalDateTime start, LocalDateTime end);
Optional<Fishing> findTopByCreatedAtGreaterThanEqualAndCreatedAtLessThanOrderByTotalIndexDesc(LocalDateTime start,
LocalDateTime end);

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

Optional<Fishing> findBySpotIdOrderByCreatedAt(Long spotId);

Optional<Fishing> findFishingBySpotIdAndForecastDateAndTimePeriod(Long spotId, LocalDate forecastDate,
TimePeriod timePeriod);
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,13 @@ Optional<BestSpotProjection> findBestSpotInScuba(@Param("latitude") double latit
""", nativeQuery = true)
List<OutdoorSpot> findByCoordinates(@Param("latitude") BigDecimal latitude,
@Param("longitude") BigDecimal longitude, @Param("limit") int limit);

@Query(value = """
SELECT * FROM outdoor_spots os
WHERE os.category = 'FISHING'
ORDER BY ST_Distance_Sphere(os.geo_point, ST_SRID(POINT(:longitude, :latitude), 4326)) ASC
LIMIT 1;
""",nativeQuery = true)
Optional<OutdoorSpot> findNearFishingSpot(@Param("latitude") double latitude,
@Param("longitude") double longitude);
}