cleanup
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m16s
Run linting on the backend code / Build (pull_request) Successful in 28s
Run testing on the backend code / Build (pull_request) Failing after 1m14s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 24s

This commit is contained in:
2025-01-23 12:01:49 +01:00
parent b9356dc4ee
commit 28ff0460ab
26 changed files with 56 additions and 196439 deletions

View File

@@ -23,44 +23,7 @@ def landmarks_to_osmid(landmarks: list[Landmark]) -> list[int] :
return ids
def fetch_landmark(client, landmark_uuid: str):
"""
Fetch landmark data from the API based on the landmark UUID.
Args:
landmark_uuid (str): The UUID of the landmark.
Returns:
dict: Landmark data fetched from the API.
"""
logger = logging.getLogger(__name__)
response = client.get(f'/landmark/{landmark_uuid}')
if response.status_code != 200:
raise HTTPException(status_code=500,
detail=f'Failed to fetch landmark with UUID {landmark_uuid}: {response.status_code}')
try:
json_data = response.json()
# logger.info(f'API Response: {json_data}')
except ValueError as e:
logger.error(f'Failed to parse response as JSON: {response.text}')
raise HTTPException(status_code=500, detail="Invalid response format from API") from e
# Try validating against the Landmark model here to ensure consistency
try:
landmark = Landmark(**json_data)
except ValidationError as ve:
logging.error(f'Validation error: {ve}')
raise HTTPException(status_code=500, detail="Invalid data format received from API") from ve
if "detail" in json_data:
raise HTTPException(status_code=500, detail=json_data["detail"])
return landmark
def fetch_landmark_cache(landmark_uuid: str):
def fetch_landmark(landmark_uuid: str):
"""
Fetch landmark data from the cache based on the landmark UUID.
@@ -91,7 +54,7 @@ def fetch_landmark_cache(landmark_uuid: str):
raise HTTPException(status_code=500, detail="An unexpected error occurred while fetching the landmark from the cache") from exc
def load_trip_landmarks(client, first_uuid: str, from_cache=None) -> list[Landmark]:
def load_trip_landmarks(client, first_uuid: str) -> list[Landmark]:
"""
Load all landmarks for a trip using the response from the API.
@@ -105,10 +68,7 @@ def load_trip_landmarks(client, first_uuid: str, from_cache=None) -> list[Landma
next_uuid = first_uuid
while next_uuid is not None:
if from_cache :
landmark = fetch_landmark_cache(next_uuid)
else :
landmark = fetch_landmark(client, next_uuid)
landmark = fetch_landmark(next_uuid)
landmarks.append(landmark)
next_uuid = landmark.next_uuid # Prepare for the next iteration