Skip to content

Commit 7ee1d5f

Browse files
committed
feat: 산 조회 쿼리에 isPublic 필터 적용
1 parent 906af9a commit 7ee1d5f

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/main/java/com/semosan/api/domain/mountain/entity/Mountain.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class Mountain extends BaseEntity {
6060
@Column(name = "location", columnDefinition = "geography(Point, 4326)")
6161
private Point location;
6262

63+
@Builder.Default
64+
@Column(name = "is_public", nullable = false)
65+
private boolean isPublic = true;
66+
6367
public void updateCoordinates(Double latitude, Double longitude) {
6468
this.latitude = latitude;
6569
this.longitude = longitude;

src/main/java/com/semosan/api/domain/mountain/repository/CourseRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public interface CourseRepository extends JpaRepository<Course, Long> {
1616
@Query("""
1717
SELECT c
1818
FROM Course c
19-
JOIN FETCH c.mountain
20-
ORDER BY c.mountain.id ASC, c.id ASC
19+
JOIN FETCH c.mountain m
20+
WHERE m.isPublic = true
21+
ORDER BY m.id ASC, c.id ASC
2122
""")
2223
List<Course> findAllWithMountainForRecommendation();
2324

src/main/java/com/semosan/api/domain/mountain/repository/MountainRepository.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414

1515
public interface MountainRepository extends JpaRepository<Mountain, Long> {
1616

17-
@Query("SELECT m FROM Mountain m WHERE m.name LIKE CONCAT('%', :keyword, '%') OR m.address LIKE CONCAT('%', :keyword, '%')")
17+
@Query("SELECT m FROM Mountain m WHERE m.isPublic = true AND (m.name LIKE CONCAT('%', :keyword, '%') OR m.address LIKE CONCAT('%', :keyword, '%'))")
1818
Page<Mountain> searchByKeyword(@Param("keyword") String keyword, Pageable pageable);
1919

20+
Page<Mountain> findByIsPublicTrue(Pageable pageable);
21+
2022
/**
2123
* 주어진 좌표(lat, lng)에서 가장 가까운 산 1개를 PostGIS 거리 연산자로 조회한다.
2224
* `<->` : PostGIS 거리 연산자, GIST 인덱스(idx_mountains_location)로 가속됨.
@@ -27,6 +29,7 @@ public interface MountainRepository extends JpaRepository<Mountain, Long> {
2729
value = """
2830
SELECT * FROM mountains
2931
WHERE location IS NOT NULL
32+
AND is_public = true
3033
ORDER BY location <-> ST_SetSRID(ST_MakePoint(:lng, :lat), 4326)::geography
3134
LIMIT 1
3235
""",
@@ -53,13 +56,15 @@ public interface MountainRepository extends JpaRepository<Mountain, Long> {
5356
WHERE difficulty IN (:difficulties)
5457
AND latitude IS NOT NULL
5558
AND longitude IS NOT NULL
59+
AND is_public = true
5660
ORDER BY (POWER(latitude - :lat, 2) + POWER((longitude - :lng) * COS(RADIANS(:lat)), 2)) ASC, id ASC
5761
""",
5862
countQuery = """
5963
SELECT COUNT(*) FROM mountains
6064
WHERE difficulty IN (:difficulties)
6165
AND latitude IS NOT NULL
6266
AND longitude IS NOT NULL
67+
AND is_public = true
6368
""",
6469
nativeQuery = true
6570
)
@@ -84,6 +89,7 @@ Page<Mountain> findRecommendationsByDifficulties(
8489
LEFT JOIN hiking_members hm ON hm.hiking_record_id = hr.id AND hm.user_id = :userId
8590
WHERE m.latitude BETWEEN :swLat AND :neLat
8691
AND m.longitude BETWEEN :swLng AND :neLng
92+
AND m.is_public = true
8793
GROUP BY m.id
8894
ORDER BY m.id
8995
""",

src/main/java/com/semosan/api/domain/mountain/service/MountainService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class MountainService {
5959

6060
public Page<MountainListResponse> getMountains(Long userId, Pageable pageable) {
6161
userReader.findActiveUserById(userId);
62-
return mountainRepository.findAll(pageable)
62+
return mountainRepository.findByIsPublicTrue(pageable)
6363
.map(MountainListResponse::from);
6464
}
6565

0 commit comments

Comments
 (0)