Skip to content

Commit

Permalink
feat: 작품 퀴즈 없을 시, 지역 퀴즈 연결 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchef1 committed Sep 30, 2024
1 parent b334104 commit e59d2de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quiz, Long> {
Optional<Quiz> findBySpot(Spot spot);
Optional<Quiz> findByCity(City city);
boolean existsBySpot(Spot spot);

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public List<AccessibleSpotResponse> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e59d2de

Please sign in to comment.