From be9c3c674763418ac978fc0b86018cd8f287f1d9 Mon Sep 17 00:00:00 2001 From: Sean Morley Date: Wed, 10 Jul 2024 13:36:51 -0400 Subject: [PATCH] starting trips --- backend/server/adventures/views.py | 2 +- documentation/docs/Installation/docker.md | 2 +- frontend/src/lib/components/TripCard.svelte | 54 +++++++++++++++++++++ frontend/src/lib/types.ts | 11 +++++ frontend/src/routes/planner/+page.svelte | 2 +- frontend/src/routes/trips/+page.server.ts | 30 ++++++++++++ frontend/src/routes/trips/+page.svelte | 53 ++++++++++++++++++++ 7 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 frontend/src/lib/components/TripCard.svelte create mode 100644 frontend/src/routes/trips/+page.server.ts create mode 100644 frontend/src/routes/trips/+page.svelte diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index 41f77b7..b03d687 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -47,7 +47,7 @@ class TripViewSet(viewsets.ModelViewSet): def get_queryset(self): return Trip.objects.filter( Q(is_public=True) | Q(user_id=self.request.user.id) - ).select_related( + ).prefetch_related( Prefetch('adventure_set', queryset=Adventure.objects.filter( Q(is_public=True) | Q(user_id=self.request.user.id) )) diff --git a/documentation/docs/Installation/docker.md b/documentation/docs/Installation/docker.md index c56665d..7548c28 100644 --- a/documentation/docs/Installation/docker.md +++ b/documentation/docs/Installation/docker.md @@ -4,7 +4,7 @@ sidebar_position: 1 # Docker 🐋 -Docker is the perffered way to run AdventureLog on your local machine. It is a lightweight containerization technology that allows you to run applications in isolated environments called containers. +Docker is the preferred way to run AdventureLog on your local machine. It is a lightweight containerization technology that allows you to run applications in isolated environments called containers. **Note**: This guide mainly focuses on installation with a linux based host machine, but the steps are similar for other operating systems. ## Prerequisites diff --git a/frontend/src/lib/components/TripCard.svelte b/frontend/src/lib/components/TripCard.svelte new file mode 100644 index 0000000..cecc556 --- /dev/null +++ b/frontend/src/lib/components/TripCard.svelte @@ -0,0 +1,54 @@ + + +
+
+

{trip.name}

+ {#if trip.date && trip.date !== ''} +
+ +

{trip.date}

+
+ {/if} + {#if trip.location && trip.location !== ''} +
+ +

{trip.location}

+
+ {/if} + +
+ + +
+
+
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 0f11e28..cba9c56 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -53,3 +53,14 @@ export type Point = { }; name: string; }; + +export type Trip = { + id: number; + user_id: number; + name: string; + type: string; + location: string; + date: string; + is_public: boolean; + adventures: Adventure[]; +}; diff --git a/frontend/src/routes/planner/+page.svelte b/frontend/src/routes/planner/+page.svelte index 993e3a2..0d8c11b 100644 --- a/frontend/src/routes/planner/+page.svelte +++ b/frontend/src/routes/planner/+page.svelte @@ -80,7 +80,7 @@ -

Visited Adventures

+

Planned Adventures

{#each adventures as adventure} diff --git a/frontend/src/routes/trips/+page.server.ts b/frontend/src/routes/trips/+page.server.ts new file mode 100644 index 0000000..f23b56a --- /dev/null +++ b/frontend/src/routes/trips/+page.server.ts @@ -0,0 +1,30 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; +import { PUBLIC_SERVER_URL } from '$env/static/public'; + +export const load = (async (event) => { + const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000'; + if (!event.locals.user || !event.cookies.get('auth')) { + return redirect(302, '/login'); + } else { + let res = await event.fetch(`${endpoint}/api/trips/`, { + headers: { + Cookies: event.cookies.get('auth') || '' + } + }); + if (res.ok) { + let data = await res.json(); + return { + props: { + trips: data + } + }; + } else { + return { + status: res.status, + error: new Error('Failed to fetch data') + }; + } + } + return {}; +}) satisfies PageServerLoad; diff --git a/frontend/src/routes/trips/+page.svelte b/frontend/src/routes/trips/+page.svelte new file mode 100644 index 0000000..a9557dd --- /dev/null +++ b/frontend/src/routes/trips/+page.svelte @@ -0,0 +1,53 @@ + + +{#if notFound} +
+
+
+ Lost +
+

+ Adventure not Found +

+

+ The adventure you were looking for could not be found. Please try a different adventure or + check back later. +

+
+ +
+
+
+{/if} + +{#if trips && !notFound} +
+ {#each trips as trip (trip.id)} + + {/each} +
+{/if}