diff --git a/backend/server/adventures/serializers.py b/backend/server/adventures/serializers.py index db01245..cd065b2 100644 --- a/backend/server/adventures/serializers.py +++ b/backend/server/adventures/serializers.py @@ -9,6 +9,9 @@ from geopy.distance import geodesic from integrations.models import ImmichIntegration import gpxpy import geojson +import logging + +logger = logging.getLogger(__name__) class ContentImageSerializer(CustomModelSerializer): @@ -88,9 +91,10 @@ class CategorySerializer(serializers.ModelSerializer): class TrailSerializer(CustomModelSerializer): provider = serializers.SerializerMethodField() + wanderer_data = serializers.SerializerMethodField() class Meta: model = Trail - fields = ['id', 'user', 'name', 'location', 'created_at','link','wanderer_id', 'provider'] + fields = ['id', 'user', 'name', 'location', 'created_at','link','wanderer_id', 'provider', 'wanderer_data'] read_only_fields = ['id', 'created_at', 'user', 'provider'] def get_provider(self, obj): @@ -108,6 +112,29 @@ class TrailSerializer(CustomModelSerializer): return 'Outdooractive' return 'External Link' + def get_wanderer_data(self, obj): + if not obj.wanderer_id: + return None + + # Fetch the Wanderer trail data + from integrations.models import WandererIntegration + from integrations.wanderer_services import fetch_trail_by_id + try: + integration = WandererIntegration.objects.filter(user=obj.user).first() + if not integration: + return None + + # Assuming there's a method to fetch trail data by ID + trail_data = fetch_trail_by_id(integration, obj.wanderer_id) + if not trail_data: + return None + obj.wanderer_data = trail_data + return trail_data + except Exception as e: + logger.error(f"Error fetching Wanderer trail data for {obj.wanderer_id}") + return None + + class ActivitySerializer(CustomModelSerializer): geojson = serializers.SerializerMethodField() diff --git a/backend/server/integrations/wanderer_services.py b/backend/server/integrations/wanderer_services.py index 5c2e68d..30b9fb1 100644 --- a/backend/server/integrations/wanderer_services.py +++ b/backend/server/integrations/wanderer_services.py @@ -108,4 +108,20 @@ def make_wanderer_request(integration: WandererIntegration, endpoint: str, metho return response except requests.RequestException as exc: logger.error(f"Error making {method} request to {url}: {exc}") - raise IntegrationError(f"Error communicating with Wanderer: {exc}") \ No newline at end of file + raise IntegrationError(f"Error communicating with Wanderer: {exc}") + +# function to fetch a specific trail by ID +def fetch_trail_by_id(integration: WandererIntegration, trail_id: str, password_for_reauth: str = None): + """ + Fetch a specific trail by its ID from the Wanderer API. + + Args: + integration: WandererIntegration instance + trail_id: ID of the trail to fetch + password_for_reauth: Password to use if re-authentication is needed + + Returns: + dict: Trail data from the API + """ + response = make_wanderer_request(integration, f"/api/v1/trail/{trail_id}", password_for_reauth=password_for_reauth) + return response.json() \ No newline at end of file diff --git a/frontend/src/lib/components/NewLocationModal.svelte b/frontend/src/lib/components/NewLocationModal.svelte index 91ba2d0..e09f853 100644 --- a/frontend/src/lib/components/NewLocationModal.svelte +++ b/frontend/src/lib/components/NewLocationModal.svelte @@ -281,6 +281,7 @@ steps[2].selected = false; steps[3].selected = true; }} + measurementSystem={user?.measurement_system || 'metric'} /> {/if} {#if steps[3].selected} diff --git a/frontend/src/lib/components/TrailCard.svelte b/frontend/src/lib/components/TrailCard.svelte deleted file mode 100644 index f4062c0..0000000 --- a/frontend/src/lib/components/TrailCard.svelte +++ /dev/null @@ -1,108 +0,0 @@ - - -