Skip to content

Commit a052e1e

Browse files
authored
Fix/fix 70 gunwoong (#71)
* hotfix: fix * hotfix: fix * hotfix: fix
1 parent 73ae7c2 commit a052e1e

File tree

55 files changed

+1634
-1458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1634
-1458
lines changed

src/main/java/sevenstar/marineleisure/forecast/domain/Fishing.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import lombok.NoArgsConstructor;
1717
import sevenstar.marineleisure.global.domain.BaseEntity;
1818
import sevenstar.marineleisure.global.enums.TidePhase;
19+
import sevenstar.marineleisure.global.enums.TimePeriod;
1920
import sevenstar.marineleisure.global.enums.TotalIndex;
2021

2122
@Entity
@@ -32,20 +33,22 @@ public class Fishing extends BaseEntity {
3233
@Column(name = "spot_id", nullable = false)
3334
private Long spotId;
3435

35-
@Column(name = "target_id", nullable = false)
36+
@Column(name = "target_id")
3637
private Long targetId;
3738

3839
@Column(name = "forecast_date", nullable = false)
3940
private LocalDate forecastDate;
4041

4142
@Column(name = "time_period", length = 10)
42-
private String timePeriod;
43+
@Enumerated(EnumType.STRING)
44+
private TimePeriod timePeriod;
4345

4446
@Column(name = "tide")
4547
@Enumerated(EnumType.STRING)
4648
private TidePhase tide;
4749

48-
@Column(name = "total_index")
50+
@Column(name = "total_index", nullable = false)
51+
@Enumerated(EnumType.STRING)
4952
private TotalIndex totalIndex;
5053

5154
@Column(name = "wave_height_min")
@@ -82,7 +85,7 @@ public class Fishing extends BaseEntity {
8285
private Float uvIndex;
8386

8487
@Builder(toBuilder = true)
85-
public Fishing(Long spotId, Long targetId, LocalDate forecastDate, String timePeriod, TidePhase tide,
88+
public Fishing(Long spotId, Long targetId, LocalDate forecastDate, TimePeriod timePeriod, TidePhase tide,
8689
TotalIndex totalIndex, Float waveHeightMin, Float waveHeightMax, Float seaTempMin, Float seaTempMax,
8790
Float airTempMin, Float airTempMax, Float currentSpeedMin, Float currentSpeedMax, Float windSpeedMin,
8891
Float windSpeedMax, Float uvIndex) {

src/main/java/sevenstar/marineleisure/forecast/domain/Scuba.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import lombok.NoArgsConstructor;
1818
import sevenstar.marineleisure.global.domain.BaseEntity;
1919
import sevenstar.marineleisure.global.enums.TidePhase;
20+
import sevenstar.marineleisure.global.enums.TimePeriod;
2021
import sevenstar.marineleisure.global.enums.TotalIndex;
2122

2223
@Entity
@@ -37,7 +38,8 @@ public class Scuba extends BaseEntity {
3738
private LocalDate forecastDate;
3839

3940
@Column(name = "time_period", length = 10, nullable = false)
40-
private String timePeriod;
41+
@Enumerated(EnumType.STRING)
42+
private TimePeriod timePeriod;
4143

4244
private LocalTime sunrise;
4345
private LocalTime sunset;
@@ -47,6 +49,7 @@ public class Scuba extends BaseEntity {
4749
private TidePhase tide;
4850

4951
@Column(name = "total_index")
52+
@Enumerated(EnumType.STRING)
5053
private TotalIndex totalIndex;
5154

5255
@Column(name = "wave_height_min")
@@ -68,7 +71,7 @@ public class Scuba extends BaseEntity {
6871
private Float currentSpeedMax;
6972

7073
@Builder
71-
public Scuba(Long spotId, LocalDate forecastDate, String timePeriod, LocalTime sunrise, LocalTime sunset,
74+
public Scuba(Long spotId, LocalDate forecastDate, TimePeriod timePeriod, LocalTime sunrise, LocalTime sunset,
7275
TidePhase tide, TotalIndex totalIndex, Float waveHeightMin, Float waveHeightMax, Float seaTempMin,
7376
Float seaTempMax, Float currentSpeedMin, Float currentSpeedMax) {
7477
this.spotId = spotId;

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
import java.util.List;
66
import java.util.Optional;
77

8-
import org.springframework.data.jpa.repository.JpaRepository;
98
import org.springframework.data.jpa.repository.Modifying;
109
import org.springframework.data.jpa.repository.Query;
1110
import org.springframework.data.repository.query.Param;
1211

1312
import jakarta.transaction.Transactional;
1413
import sevenstar.marineleisure.forecast.domain.Fishing;
15-
import sevenstar.marineleisure.global.enums.TimePeriod;
16-
import sevenstar.marineleisure.global.enums.TotalIndex;
17-
import sevenstar.marineleisure.spot.dto.FishingReadResponse;
14+
import sevenstar.marineleisure.spot.dto.projection.FishingReadProjection;
15+
import sevenstar.marineleisure.spot.repository.ActivityRepository;
1816

19-
public interface FishingRepository extends JpaRepository<Fishing, Long> {
17+
public interface FishingRepository extends ActivityRepository<Fishing, Long> {
2018
@Query(value = """
2119
SELECT DISTINCT f.spotId FROM Fishing f
2220
WHERE f.forecastDate BETWEEN :forecastDateAfter AND :forecastDateBefore
@@ -25,19 +23,31 @@ List<Long> findByForecastDateBetween(@Param("forecastDateAfter") LocalDate forec
2523
@Param("forecastDateBefore") LocalDate forecastDateBefore);
2624

2725
@Query("""
28-
SELECT new sevenstar.marineleisure.spot.dto.FishingReadResponse(:spotId,ft.id,ft.name,f.forecastDate,f.timePeriod,f.tide,f.totalIndex,f.waveHeightMin,f.waveHeightMax,f.seaTempMin,f.seaTempMax,f.airTempMin,f.airTempMax,f.currentSpeedMin,f.currentSpeedMax,f.windSpeedMin,f.windSpeedMax,f.uvIndex) FROM Fishing f
26+
SELECT
27+
f.forecastDate AS forecastDate,
28+
f.timePeriod AS timePeriod,
29+
f.tide AS tide,
30+
f.totalIndex AS totalIndex,
31+
f.waveHeightMin AS waveHeightMin,
32+
f.waveHeightMax AS waveHeightMax,
33+
f.seaTempMin AS seaTempMin,
34+
f.seaTempMax AS seaTempMax,
35+
f.airTempMin AS airTempMin,
36+
f.airTempMax AS airTempMax,
37+
f.currentSpeedMin AS currentSpeedMin,
38+
f.currentSpeedMax AS currentSpeedMax,
39+
f.windSpeedMin AS windSpeedMin,
40+
f.windSpeedMax AS windSpeedMax,
41+
f.uvIndex AS uvIndex,
42+
ft.id AS targetId,
43+
ft.name AS targetName
44+
45+
FROM Fishing f
2946
LEFT JOIN FishingTarget ft ON f.targetId = ft.id
3047
WHERE f.spotId = :spotId
31-
AND f.forecastDate = :date
48+
AND f.forecastDate = :date
3249
""")
33-
List<FishingReadResponse> findFishingForecasts(@Param("spotId") Long spotId, @Param("date") LocalDate date);
34-
35-
@Query("""
36-
SELECT f.totalIndex
37-
FROM Fishing f
38-
WHERE f.spotId = :spotId AND f.forecastDate = :date AND f.timePeriod = :timePeriod
39-
""")
40-
Optional<TotalIndex> findTotalIndexBySpotIdAndDate(@Param("spotId") Long spotId, @Param("date") LocalDate date,@Param("timePeriod") TimePeriod timePeriod);
50+
List<FishingReadProjection> findForecastsWithFish(@Param("spotId") Long spotId, @Param("date") LocalDate date);
4151

4252
@Modifying
4353
@Transactional
@@ -112,5 +122,4 @@ Optional<Fishing> findFirstBySpotIdAndCreatedAtGreaterThanEqualAndCreatedAtLessT
112122
Optional<Fishing> findBySpotIdAndCreatedAtBeforeOrderByCreatedAtDesc(Long spotId, LocalDateTime createdAtBefore);
113123

114124
Optional<Fishing> findBySpotIdOrderByCreatedAt(Long spotId);
115-
116-
}
125+
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,22 @@
66
import java.util.List;
77
import java.util.Optional;
88

9-
import org.springframework.data.jpa.repository.JpaRepository;
109
import org.springframework.data.jpa.repository.Modifying;
1110
import org.springframework.data.jpa.repository.Query;
1211
import org.springframework.data.repository.query.Param;
1312

1413
import jakarta.transaction.Transactional;
1514
import sevenstar.marineleisure.forecast.domain.Mudflat;
16-
import sevenstar.marineleisure.global.enums.TotalIndex;
15+
import sevenstar.marineleisure.spot.repository.ActivityRepository;
1716

18-
public interface MudflatRepository extends JpaRepository<Mudflat, Long> {
17+
public interface MudflatRepository extends ActivityRepository<Mudflat, Long> {
1918
@Query(value = """
2019
SELECT DISTINCT m.spotId FROM Mudflat m
2120
WHERE m.forecastDate BETWEEN :forecastDateAfter AND :forecastDateBefore
2221
""")
2322
List<Long> findByForecastDateBetween(@Param("forecastDateAfter") LocalDate forecastDateAfter,
2423
@Param("forecastDateBefore") LocalDate forecastDateBefore);
2524

26-
Optional<Mudflat> findBySpotIdAndForecastDate(Long spotId, LocalDate forecastDate);
27-
28-
@Query("""
29-
SELECT m.totalIndex
30-
FROM Mudflat m
31-
WHERE m.spotId = :spotId AND m.forecastDate = :date
32-
""")
33-
Optional<TotalIndex> findTotalIndexBySpotIdAndDate(@Param("spotId") Long spotId, @Param("date") LocalDate date);
34-
3525
@Modifying
3626
@Transactional
3727
@Query(value = """

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,22 @@
66
import java.util.List;
77
import java.util.Optional;
88

9-
import org.springframework.data.jpa.repository.JpaRepository;
109
import org.springframework.data.jpa.repository.Modifying;
1110
import org.springframework.data.jpa.repository.Query;
1211
import org.springframework.data.repository.query.Param;
1312

1413
import jakarta.transaction.Transactional;
1514
import sevenstar.marineleisure.forecast.domain.Scuba;
16-
import sevenstar.marineleisure.global.enums.TimePeriod;
17-
import sevenstar.marineleisure.global.enums.TotalIndex;
15+
import sevenstar.marineleisure.spot.repository.ActivityRepository;
1816

19-
public interface ScubaRepository extends JpaRepository<Scuba, Long> {
17+
public interface ScubaRepository extends ActivityRepository<Scuba, Long> {
2018
@Query(value = """
2119
SELECT DISTINCT s.spotId FROM Scuba s
2220
WHERE s.forecastDate BETWEEN :forecastDateAfter AND :forecastDateBefore
2321
""")
2422
List<Long> findByForecastDateBetween(@Param("forecastDateAfter") LocalDate forecastDateAfter,
2523
@Param("forecastDateBefore") LocalDate forecastDateBefore);
2624

27-
@Query("""
28-
SELECT s FROM Scuba s
29-
WHERE s.spotId = :spotId
30-
AND s.forecastDate = :date
31-
""")
32-
List<Scuba> findScubaForecasts(@Param("spotId") Long spotId, @Param("date") LocalDate date);
33-
34-
@Query("""
35-
SELECT s.totalIndex
36-
FROM Scuba s
37-
WHERE s.spotId = :spotId AND s.forecastDate = :date AND s.timePeriod = :timePeriod
38-
""")
39-
Optional<TotalIndex> findTotalIndexBySpotIdAndDate(@Param("spotId") Long spotId, @Param("date") LocalDate date,@Param("timePeriod") TimePeriod timePeriod);
40-
4125
@Modifying
4226
@Transactional
4327
@Query(value = """
@@ -99,6 +83,4 @@ Optional<Scuba> findFirstBySpotIdAndCreatedAtGreaterThanEqualAndCreatedAtLessTha
9983
Long spotId,
10084
LocalDateTime startDateTime,
10185
LocalDateTime endDateTime);
102-
103-
// Optional<Scuba> findBySpotIdOrderByCreatedAt(Long spotId);
10486
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
import java.util.List;
66
import java.util.Optional;
77

8-
import org.springframework.data.jpa.repository.JpaRepository;
98
import org.springframework.data.jpa.repository.Modifying;
109
import org.springframework.data.jpa.repository.Query;
1110
import org.springframework.data.repository.query.Param;
1211

1312
import jakarta.transaction.Transactional;
1413
import sevenstar.marineleisure.forecast.domain.Surfing;
15-
import sevenstar.marineleisure.global.enums.TimePeriod;
16-
import sevenstar.marineleisure.global.enums.TotalIndex;
14+
import sevenstar.marineleisure.spot.repository.ActivityRepository;
1715

18-
public interface SurfingRepository extends JpaRepository<Surfing, Long> {
16+
public interface SurfingRepository extends ActivityRepository<Surfing, Long> {
1917
@Query(value = """
2018
SELECT DISTINCT s.spotId FROM Surfing s
2119
WHERE s.forecastDate BETWEEN :forecastDateAfter AND :forecastDateBefore
@@ -30,13 +28,6 @@ List<Long> findByForecastDateBetween(@Param("forecastDateAfter") LocalDate forec
3028
""")
3129
List<Surfing> findSurfingForecasts(@Param("spotId") Long spotId, @Param("date") LocalDate date);
3230

33-
@Query("""
34-
SELECT s.totalIndex
35-
FROM Surfing s
36-
WHERE s.spotId = :spotId AND s.forecastDate = :date AND s.timePeriod = :timePeriod
37-
""")
38-
Optional<TotalIndex> findTotalIndexBySpotIdAndDate(@Param("spotId") Long spotId, @Param("date") LocalDate date,@Param("timePeriod") TimePeriod timePeriod);
39-
4031
@Modifying
4132
@Transactional
4233
@Query(value = """

src/main/java/sevenstar/marineleisure/global/api/khoa/KhoaApiClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sevenstar.marineleisure.global.api.khoa;
22

33
import java.net.URI;
4+
import java.time.LocalDate;
45

56
import org.springframework.core.ParameterizedTypeReference;
67
import org.springframework.http.HttpMethod;
@@ -13,6 +14,8 @@
1314
import sevenstar.marineleisure.global.api.khoa.dto.common.ApiResponse;
1415
import sevenstar.marineleisure.global.api.khoa.dto.item.FishingItem;
1516
import sevenstar.marineleisure.global.enums.ActivityCategory;
17+
import sevenstar.marineleisure.global.enums.FishingType;
18+
import sevenstar.marineleisure.global.utils.DateUtils;
1619
import sevenstar.marineleisure.global.utils.UriBuilder;
1720

1821
@Component
@@ -31,14 +34,14 @@ public class KhoaApiClient {
3134
* @return response
3235
* @param <T>
3336
*/
34-
public <T> ResponseEntity<T> get(ParameterizedTypeReference<T> responseType, String reqDate, int page, int size,
37+
public <T> ResponseEntity<T> get(ParameterizedTypeReference<T> responseType, LocalDate reqDate, int page, int size,
3538
ActivityCategory category) {
3639
if (category == ActivityCategory.FISHING) {
3740
// TODO : handling exception
3841
// throw new IllegalAccessException();
3942
}
4043
URI uri = UriBuilder.buildQueryParameter(khoaProperties.getBaseUrl(), khoaProperties.getPath(category),
41-
khoaProperties.getParams(reqDate, page, size));
44+
khoaProperties.getParams(DateUtils.formatTime(reqDate), page, size));
4245
return restTemplate.exchange(uri, HttpMethod.GET, null, responseType);
4346
}
4447

@@ -52,10 +55,10 @@ public <T> ResponseEntity<T> get(ParameterizedTypeReference<T> responseType, Str
5255
* @return response
5356
*/
5457
public ResponseEntity<ApiResponse<FishingItem>> get(
55-
ParameterizedTypeReference<ApiResponse<FishingItem>> responseType, String reqDate, int page, int size,
56-
String gubun) {
58+
ParameterizedTypeReference<ApiResponse<FishingItem>> responseType, LocalDate reqDate, int page, int size,
59+
FishingType gubun) {
5760
URI uri = UriBuilder.buildQueryParameter(khoaProperties.getBaseUrl(),
58-
khoaProperties.getPath(ActivityCategory.FISHING), khoaProperties.getParams(reqDate, page, size, gubun));
61+
khoaProperties.getPath(ActivityCategory.FISHING), khoaProperties.getParams(DateUtils.formatTime(reqDate), page, size, gubun.getDescription()));
5962
return restTemplate.exchange(uri, HttpMethod.GET, null, responseType);
6063
}
6164

src/main/java/sevenstar/marineleisure/global/api/khoa/dto/item/FishingItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sevenstar.marineleisure.global.api.khoa.dto.item;
22

33
import java.math.BigDecimal;
4+
import java.time.LocalDate;
45

56
import lombok.Getter;
67
import sevenstar.marineleisure.global.enums.ActivityCategory;
8+
import sevenstar.marineleisure.global.utils.DateUtils;
79

810
@Getter
911
public class FishingItem implements KhoaItem {
@@ -46,4 +48,9 @@ public BigDecimal getLongitude() {
4648
public ActivityCategory getCategory() {
4749
return ActivityCategory.FISHING;
4850
}
51+
52+
@Override
53+
public LocalDate getForecastDate() {
54+
return DateUtils.parseDate(predcYmd);
55+
}
4956
}

src/main/java/sevenstar/marineleisure/global/api/khoa/dto/item/KhoaItem.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sevenstar.marineleisure.global.api.khoa.dto.item;
22

33
import java.math.BigDecimal;
4+
import java.time.LocalDate;
45

56
import sevenstar.marineleisure.global.enums.ActivityCategory;
67

@@ -12,4 +13,6 @@ public interface KhoaItem {
1213
BigDecimal getLongitude();
1314

1415
ActivityCategory getCategory();
16+
17+
LocalDate getForecastDate();
1518
}

src/main/java/sevenstar/marineleisure/global/api/khoa/dto/item/MudflatItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sevenstar.marineleisure.global.api.khoa.dto.item;
22

33
import java.math.BigDecimal;
4+
import java.time.LocalDate;
45

56
import lombok.Getter;
67
import sevenstar.marineleisure.global.enums.ActivityCategory;
8+
import sevenstar.marineleisure.global.utils.DateUtils;
79

810
@Getter
911
public class MudflatItem implements KhoaItem {
@@ -40,4 +42,9 @@ public BigDecimal getLongitude() {
4042
public ActivityCategory getCategory() {
4143
return ActivityCategory.MUDFLAT;
4244
}
45+
46+
@Override
47+
public LocalDate getForecastDate() {
48+
return DateUtils.parseDate(predcYmd);
49+
}
4350
}

0 commit comments

Comments
 (0)