From e59d2de374d9e21db158b752ddc14d084bd6f1ca Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 30 Sep 2024 20:52:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=91=ED=92=88=20=ED=80=B4=EC=A6=88?= =?UTF-8?q?=20=EC=97=86=EC=9D=84=20=EC=8B=9C,=20=EC=A7=80=EC=97=AD=20?= =?UTF-8?q?=ED=80=B4=EC=A6=88=20=EC=97=B0=EA=B2=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spotserver/api/quiz/repository/QuizRepository.java | 3 +++ .../spot/spotserver/api/spot/service/SpotService.java | 10 ++++++---- .../spot/spotserver/common/payload/SuccessCode.java | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/spot/spotserver/api/quiz/repository/QuizRepository.java b/src/main/java/com/spot/spotserver/api/quiz/repository/QuizRepository.java index 1b829ea..5eebcb5 100644 --- a/src/main/java/com/spot/spotserver/api/quiz/repository/QuizRepository.java +++ b/src/main/java/com/spot/spotserver/api/quiz/repository/QuizRepository.java @@ -2,11 +2,14 @@ import com.spot.spotserver.api.quiz.domain.Quiz; import com.spot.spotserver.api.spot.domain.Spot; +import com.spot.spotserver.common.domain.City; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; public interface QuizRepository extends JpaRepository { Optional findBySpot(Spot spot); + Optional findByCity(City city); boolean existsBySpot(Spot spot); + } diff --git a/src/main/java/com/spot/spotserver/api/spot/service/SpotService.java b/src/main/java/com/spot/spotserver/api/spot/service/SpotService.java index fc02ff3..41415ad 100644 --- a/src/main/java/com/spot/spotserver/api/spot/service/SpotService.java +++ b/src/main/java/com/spot/spotserver/api/spot/service/SpotService.java @@ -77,10 +77,12 @@ public List getAccessibleSpot(double userLatitude, doubl .filter(this.quizRepository::existsBySpot) .sorted(Comparator.comparing((spot) -> this.calculateDistance(userLatitude, userLongitude, spot.getLatitude(), spot.getLongitude()))) .limit(QUIZ_COUNT) - .map((spot) -> this.quizRepository.findBySpot(spot) - .map(quiz -> new AccessibleSpotResponse(spot, quiz.getId())) - .orElse(null)) - .filter(Objects::nonNull) + .map((spot) -> { + Quiz quiz = this.quizRepository.findBySpot(spot) + .or(() -> this.quizRepository.findByCity(spot.getCity())) + .orElseThrow(); + return new AccessibleSpotResponse(spot, quiz.getId()); + }) .toList(); } diff --git a/src/main/java/com/spot/spotserver/common/payload/SuccessCode.java b/src/main/java/com/spot/spotserver/common/payload/SuccessCode.java index ee19724..77d6105 100644 --- a/src/main/java/com/spot/spotserver/common/payload/SuccessCode.java +++ b/src/main/java/com/spot/spotserver/common/payload/SuccessCode.java @@ -63,7 +63,8 @@ public enum SuccessCode { DELETE_LOCATIONS_SUCCESS(OK, "장소들이 정상적으로 삭제되었습니다."), GET_SELECTED_SPOT_SUCCESS(OK, "해당 일정의 담은 장소들이 정상적으로 조회되었습니다."), SELECT_SPOT_SUCCESS(OK, "장소들이 일정에 정상적으로 담겼습니다."), - CREATE_BADGE_SUCCESS(OK, "뱃지가 정상적으로 생성되었습니다."); + CREATE_BADGE_SUCCESS(OK, "뱃지가 정상적으로 생성되었습니다."), + UPDATE_LOCATION_POSITION_SUCCESS(OK, "장소의 위치가 정상적으로 변경되었습니다."); private final HttpStatus httpStatus; private final String message;