diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index e981fcc..dbbc280 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -151,12 +151,46 @@ class AdventureViewSet(viewsets.ModelViewSet): @action(detail=False, methods=['get']) def search(self, request): query = self.request.query_params.get('query', '') + property = self.request.query_params.get('property', 'all') if len(query) < 2: return Response({"error": "Query must be at least 2 characters long"}, status=400) - queryset = Adventure.objects.filter( - (Q(name__icontains=query) | Q(description__icontains=query) | Q(location__icontains=query) | Q(activity_types__icontains=query)) & - (Q(user_id=request.user.id) | Q(is_public=True)) -) + + if property not in ['name', 'type', 'location', 'description', 'activity_types']: + property = 'all' + + queryset = Adventure.objects.none() + + if property == 'name': + queryset = Adventure.objects.filter( + (Q(name__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + elif property == 'type': + queryset = Adventure.objects.filter( + (Q(type__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + elif property == 'location': + queryset = Adventure.objects.filter( + (Q(location__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + elif property == 'description': + queryset = Adventure.objects.filter( + (Q(description__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + elif property == 'activity_types': + queryset = Adventure.objects.filter( + (Q(activity_types__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + else: + queryset = Adventure.objects.filter( + (Q(name__icontains=query) | Q(description__icontains=query) | Q(location__icontains=query) | Q(activity_types__icontains=query)) & + (Q(user_id=request.user.id) | Q(is_public=True)) + ) + queryset = self.apply_sorting(queryset) serializer = self.get_serializer(queryset, many=True) return Response(serializer.data) diff --git a/frontend/src/lib/components/AboutModal.svelte b/frontend/src/lib/components/AboutModal.svelte index 2670c73..0ffdb55 100644 --- a/frontend/src/lib/components/AboutModal.svelte +++ b/frontend/src/lib/components/AboutModal.svelte @@ -64,6 +64,7 @@ class="text-primary-500 underline" href="https://operations.osmfoundation.org/policies/nominatim/">OpenStreepMap. Their data is liscensed under the ODbL liscense. +
Additional attributions can be found in the README file.

diff --git a/frontend/src/routes/search/+page.server.ts b/frontend/src/routes/search/+page.server.ts index 0d270da..de98f84 100644 --- a/frontend/src/routes/search/+page.server.ts +++ b/frontend/src/routes/search/+page.server.ts @@ -7,17 +7,21 @@ const serverEndpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; export const load = (async (event) => { // get url param query const query = event.url.searchParams.get('query'); + const property = event.url.searchParams.get('property') || 'all'; if (!query) { return { data: [] }; } - let res = await fetch(`${serverEndpoint}/api/adventures/search/?query=${query}`, { - headers: { - 'Content-Type': 'application/json', - Cookie: `${event.cookies.get('auth')}` + let res = await fetch( + `${serverEndpoint}/api/adventures/search/?query=${query}&property=${property}`, + { + headers: { + 'Content-Type': 'application/json', + Cookie: `${event.cookies.get('auth')}` + } } - }); + ); if (res.ok) { let data = await res.json(); diff --git a/frontend/src/routes/search/+page.svelte b/frontend/src/routes/search/+page.svelte index 54476cf..fca5bbf 100644 --- a/frontend/src/routes/search/+page.svelte +++ b/frontend/src/routes/search/+page.svelte @@ -6,17 +6,28 @@ import type { PageData } from './$types'; import EditAdventure from '$lib/components/EditAdventure.svelte'; import { appVersion } from '$lib/config'; + import { goto, invalidate } from '$app/navigation'; export let data: PageData; function deleteAdventure(event: CustomEvent) { - adventures = adventures.filter((adventure) => adventure.id !== event.detail); + myAdventures = myAdventures.filter((adventure) => adventure.id !== event.detail); } let osmResults: OpenStreetMapPlace[] = []; - let adventures: Adventure[] = []; + let myAdventures: Adventure[] = []; + let publicAdventures: Adventure[] = []; let query: string | null = ''; + let property: string = 'all'; + + // on chage of property, console log the property + + function filterByProperty() { + let url = new URL(window.location.href); + url.searchParams.set('property', property); + goto(url.toString(), { invalidateAll: true }); + } onMount(() => { const urlParams = new URLSearchParams(window.location.search); @@ -46,9 +57,23 @@ }); console.log(data); + $: { + if (data.props) { + myAdventures = data.props.adventures; + publicAdventures = data.props.adventures; - if (data.props) { - adventures = data.props.adventures; + if (data.user?.pk != null) { + myAdventures = myAdventures.filter( + (adventure) => adventure.user_id === data.user?.pk ?? -1 + ); + } else { + myAdventures = []; + } + + publicAdventures = publicAdventures.filter( + (adventure) => adventure.user_id !== data.user?.pk + ); + } } let adventureToEdit: Adventure; @@ -61,7 +86,7 @@ } function saveEdit(event: CustomEvent) { - adventures = adventures.map((adventure) => { + myAdventures = myAdventures.map((adventure) => { if (adventure.id === event.detail.id) { return event.detail; } @@ -79,14 +104,72 @@ /> {/if} -{#if adventures.length === 0 && osmResults.length === 0} +{#if myAdventures.length === 0 && osmResults.length === 0} {/if} -{#if adventures.length > 0} +{#if myAdventures.length !== 0 && publicAdventures.length !== 0}

AdventureLog Results

+{/if} +
+
+ (property = 'all')} + /> + (property = 'name')} + /> + (property = 'type')} + /> + (property = 'location')} + /> + (property = 'description')} + /> + (property = 'activity_types')} + /> +
+ +
+ +{#if myAdventures.length > 0} +

My Adventures

- {#each adventures as adventure} + {#each myAdventures as adventure} {/if} -{#if adventures.length > 0 && osmResults.length > 0} + +{#if publicAdventures.length > 0} +

Public Adventures

+
+ {#each publicAdventures as adventure} + + {/each} +
+{/if} +{#if myAdventures.length > 0 && osmResults.length > 0 && publicAdventures.length > 0}
{/if} {#if osmResults.length > 0}