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 @@ -588,10 +588,13 @@ public ResponseEntity<BaseResponse<SearchSightList>> searchTitle(
@RequestParam(defaultValue = "10")
@Min(value = 1, message = "제한 개수는 1 이상이어야 합니다")
@Max(value = 100, message = "제한 개수는 100 이하여야 합니다")
Integer limit
Integer limit,

@RequestHeader(value = "X-USER-ID", required = false)
Long memberId
) {
return ResponseEntity.ok(BaseResponse.ok(
sightService.searchSight(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit, "ko")
sightService.searchSight(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit, "ko", memberId)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public record SearchSightItemDto(
String addr3,
Double mapX,
Double mapY,
Double distance
Double distance,
boolean isBookmark
) {
}
6 changes: 6 additions & 0 deletions src/main/java/com/earseo/sight/dto/response/LocationType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.earseo.sight.dto.response;

public enum LocationType {
SIGHT,
BOOKMARK
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public record SearchSightResponse(
Double latitude,

@Schema(description = "현재 위치로부터의 직선 거리 (미터)", example = "1234.56")
Double distance
Double distance,

LocationType locationType
) {
public static SearchSightResponse toDto(SearchSightItemDto dto){
return new SearchSightResponse(
Expand All @@ -34,7 +36,8 @@ public static SearchSightResponse toDto(SearchSightItemDto dto){
dto.addr3(),
dto.mapX(),
dto.mapY(),
dto.distance()
dto.distance(),
dto.isBookmark() ? LocationType.BOOKMARK : LocationType.SIGHT
);
}
}
21 changes: 15 additions & 6 deletions src/main/java/com/earseo/sight/repository/EnSightRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ List<CurationSightItemDto> findByCurationId(
ST_Distance(
s.geom::geography,
ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)::geography
) as distance
) as distance,
CASE WHEN :memberId IS NOT NULL AND sb.id IS NOT NULL
THEN true
ELSE false
END as is_bookmark
FROM en_sight s
LEFT JOIN sight_bookmark sb
ON sb.content_id = s.content_id
AND sb.member_id = :memberId
WHERE ST_Intersects(
s.geom,
ST_MakeEnvelope(:minLongitude, :minLatitude, :maxLongitude, :maxLatitude, 4326)
) AND
:keyword IS NULL OR
:keyword = '' OR
s.title ILIKE '%' || :keyword || '%'
) AND (
:keyword IS NULL OR
:keyword = '' OR
s.title ILIKE '%' || :keyword || '%'
)
ORDER BY distance
LIMIT :limit
""", nativeQuery = true)
Expand All @@ -118,6 +126,7 @@ List<SearchSightItemDto> findByKeywordAndRectangle(
@Param("minLatitude") Double minLatitude,
@Param("maxLongitude") Double maxLongitude,
@Param("maxLatitude") Double maxLatitude,
@Param("limit") Integer limit
@Param("limit") Integer limit,
@Param("memberId") Long memberId
);
}
21 changes: 15 additions & 6 deletions src/main/java/com/earseo/sight/repository/KoSightRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ List<CurationSightItemDto> findByCurationId(
ST_Distance(
s.geom::geography,
ST_SetSRID(ST_MakePoint(:longitude, :latitude), 4326)::geography
) as distance
) as distance,
CASE WHEN :memberId IS NOT NULL AND sb.id IS NOT NULL
THEN true
ELSE false
END as is_bookmark
FROM ko_sight s
LEFT JOIN sight_bookmark sb
ON sb.content_id = s.content_id
AND sb.member_id = :memberId
WHERE ST_Intersects(
s.geom,
ST_MakeEnvelope(:minLongitude, :minLatitude, :maxLongitude, :maxLatitude, 4326)
) AND
:keyword IS NULL OR
:keyword = '' OR
s.title ILIKE '%' || :keyword || '%'
) AND (
:keyword IS NULL OR
:keyword = '' OR
s.title ILIKE '%' || :keyword || '%'
)
ORDER BY distance
LIMIT :limit
""", nativeQuery = true)
Expand All @@ -118,6 +126,7 @@ List<SearchSightItemDto> findByKeywordAndRectangle(
@Param("minLatitude") Double minLatitude,
@Param("maxLongitude") Double maxLongitude,
@Param("maxLatitude") Double maxLatitude,
@Param("limit") Integer limit
@Param("limit") Integer limit,
@Param("memberId") Long memberId
);
}
6 changes: 3 additions & 3 deletions src/main/java/com/earseo/sight/service/SightService.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ public DocentResponse getDocent(String sightId) {
public SearchSightList searchSight(
String keyword, Double longitude, Double latitude,
Double minLongitude, Double minLatitude,
Double maxLongitude, Double maxLatitude, Integer limit, String lang) {
Double maxLongitude, Double maxLatitude, Integer limit, String lang, Long memberId) {
if (minLongitude >= maxLongitude || minLatitude >= maxLatitude) {
throw new BaseException(SightError.INVALID_COORDINATE_RANGE);
}

List<SearchSightItemDto> sights;
if (lang.equals("en")) {
sights = enSightRepository.findByKeywordAndRectangle(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit);
sights = enSightRepository.findByKeywordAndRectangle(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit, memberId);
} else {
sights = koSightRepository.findByKeywordAndRectangle(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit);
sights = koSightRepository.findByKeywordAndRectangle(keyword, longitude, latitude, minLongitude, minLatitude, maxLongitude, maxLatitude, limit, memberId);
}
List<SearchSightResponse> sightResponses = sights.stream()
.map(SearchSightResponse::toDto)
Expand Down
Loading