diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py
index f7a27308..496ded22 100644
--- a/backend/server/adventures/views.py
+++ b/backend/server/adventures/views.py
@@ -27,13 +27,37 @@ class AdventureViewSet(viewsets.ModelViewSet):
permission_classes = [IsOwnerOrReadOnly, IsPublicReadOnly]
pagination_class = StandardResultsSetPagination
+ def apply_sorting(self, queryset):
+ order_by = self.request.query_params.get('order_by', 'name')
+ order_direction = self.request.query_params.get('order_direction', 'asc')
+
+ valid_order_by = ['name', 'type', 'date', 'rating']
+ if order_by not in valid_order_by:
+ order_by = 'name'
+
+ if order_direction not in ['asc', 'desc']:
+ order_direction = 'asc'
+
+ # Apply case-insensitive sorting for the 'name' field
+ if order_by == 'name':
+ queryset = queryset.annotate(lower_name=Lower('name'))
+ ordering = 'lower_name'
+ else:
+ ordering = order_by
+
+ if order_direction == 'desc':
+ ordering = f'-{ordering}'
+
+ print(f"Ordering by: {ordering}") # For debugging
+
+ return queryset.order_by(ordering)
+
def get_queryset(self):
- lower_name = Lower('name')
queryset = Adventure.objects.annotate(
).filter(
Q(is_public=True) | Q(user_id=self.request.user.id)
- ).order_by(lower_name) # Sort by the annotated lowercase name
- return queryset
+ )
+ return self.apply_sorting(queryset)
def perform_create(self, serializer):
serializer.save(user_id=self.request.user)
@@ -57,10 +81,17 @@ def filtered(self, request):
queryset |= Adventure.objects.filter(
type='featured', is_public=True, trip=None)
- lower_name = Lower('name')
- queryset = queryset.order_by(lower_name)
+ queryset = self.apply_sorting(queryset)
adventures = self.paginate_and_respond(queryset, request)
return adventures
+
+ @action(detail=False, methods=['get'])
+ def all(self, request):
+ if not request.user.is_authenticated:
+ return Response({"error": "User is not authenticated"}, status=400)
+ queryset = Adventure.objects.filter(user_id=request.user.id).exclude(type='featured')
+ serializer = self.get_serializer(queryset, many=True)
+ return Response(serializer.data)
def paginate_and_respond(self, queryset, request):
paginator = self.pagination_class()
@@ -70,7 +101,6 @@ def paginate_and_respond(self, queryset, request):
return paginator.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
-
class TripViewSet(viewsets.ModelViewSet):
serializer_class = TripSerializer
permission_classes = [IsOwnerOrReadOnly, IsPublicReadOnly]
diff --git a/docker-compose.yml b/docker-compose.yml
index 90e3194f..7ffadebf 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -2,8 +2,8 @@ version: "3.9"
services:
web:
- build: ./frontend/
- #image: ghcr.io/seanmorley15/adventurelog-frontend:latest
+ #build: ./frontend/
+ image: ghcr.io/seanmorley15/adventurelog-frontend:latest
environment:
- PUBLIC_SERVER_URL=http://server:8000
- ORIGIN=http://localhost:8080
@@ -23,8 +23,8 @@ services:
- postgres_data:/var/lib/postgresql/data/
server:
- build: ./backend/
- #image: ghcr.io/seanmorley15/adventurelog-backend:latest
+ #build: ./backend/
+ image: ghcr.io/seanmorley15/adventurelog-backend:latest
environment:
- PGHOST=db
- PGDATABASE=database
diff --git a/frontend/src/lib/components/Avatar.svelte b/frontend/src/lib/components/Avatar.svelte
index b1d35d83..bb3833e3 100644
--- a/frontend/src/lib/components/Avatar.svelte
+++ b/frontend/src/lib/components/Avatar.svelte
@@ -30,7 +30,7 @@
Hi, {user.first_name} {user.last_name}
-
+
+
+ View
+
+ (currentView = 'cards')}
+ checked
+ />
+ (currentView = 'table')}
+ />
+
diff --git a/frontend/src/routes/featured/+page.server.ts b/frontend/src/routes/featured/+page.server.ts
deleted file mode 100644
index 1d3d4db0..00000000
--- a/frontend/src/routes/featured/+page.server.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { redirect } from '@sveltejs/kit';
-import type { PageServerLoad } from './$types';
-const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
-import type { Adventure } from '$lib/types';
-const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
-
-export const load = (async (event) => {
- if (!event.locals.user) {
- return redirect(302, '/login');
- } else {
- let visitedFetch = await fetch(`${endpoint}/api/adventures/featured/`, {
- headers: {
- Cookie: `${event.cookies.get('auth')}`
- }
- });
- if (!visitedFetch.ok) {
- console.error('Failed to fetch featured adventures');
- return redirect(302, '/login');
- } else {
- let featured = (await visitedFetch.json()) as Adventure[];
- return {
- props: {
- featured
- }
- };
- }
- }
-}) satisfies PageServerLoad;
diff --git a/frontend/src/routes/featured/+page.svelte b/frontend/src/routes/featured/+page.svelte
deleted file mode 100644
index 3ee5473c..00000000
--- a/frontend/src/routes/featured/+page.svelte
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-Featured Adventures
-
- {#each adventures as adventure}
-
- {/each}
-
-
-{#if adventures.length === 0}
-
-
No visited adventures yet!
-
-{/if}
diff --git a/frontend/src/routes/map/+page.server.ts b/frontend/src/routes/map/+page.server.ts
index 44e935cc..24659520 100644
--- a/frontend/src/routes/map/+page.server.ts
+++ b/frontend/src/routes/map/+page.server.ts
@@ -8,7 +8,7 @@ export const load = (async (event) => {
if (!event.locals.user) {
return redirect(302, '/login');
} else {
- let visitedFetch = await fetch(`${endpoint}/api/adventures/`, {
+ let visitedFetch = await fetch(`${endpoint}/api/adventures/all/`, {
headers: {
Cookie: `${event.cookies.get('auth')}`
}
diff --git a/frontend/src/routes/planner/+page.server.ts b/frontend/src/routes/planner/+page.server.ts
deleted file mode 100644
index fcdc109e..00000000
--- a/frontend/src/routes/planner/+page.server.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { redirect } from '@sveltejs/kit';
-import type { PageServerLoad } from './$types';
-const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
-import type { Adventure } from '$lib/types';
-const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
-
-export const load = (async (event) => {
- if (!event.locals.user) {
- return redirect(302, '/login');
- } else {
- let plannedFetch = await fetch(`${endpoint}/api/adventures/planned/`, {
- headers: {
- Cookie: `${event.cookies.get('auth')}`
- }
- });
- if (!plannedFetch.ok) {
- console.error('Failed to fetch planned adventures');
- return redirect(302, '/login');
- } else {
- let planned = (await plannedFetch.json()) as Adventure[];
- return {
- props: {
- planned
- }
- };
- }
- }
-}) satisfies PageServerLoad;
diff --git a/frontend/src/routes/planner/+page.svelte b/frontend/src/routes/planner/+page.svelte
deleted file mode 100644
index 00d216fd..00000000
--- a/frontend/src/routes/planner/+page.svelte
+++ /dev/null
@@ -1,111 +0,0 @@
-
-
-{#if isShowingCreateModal}
- (isShowingCreateModal = false)}
- />
-{/if}
-
-{#if isEditModalOpen}
- (isEditModalOpen = false)}
- on:saveEdit={saveEdit}
- />
-{/if}
-
-
-
-
-
-
-
- Create new...
-
-
-
-
-
-
-
-{#if adventures.length > 0}
- Planned Adventures
-{/if}
-
-
- {#each adventures as adventure}
-
- {/each}
-
-
-{#if adventures.length === 0}
-
-
-
-
-
-
- No planned adventures found
-
-
- There are no adventures to display. Add some using the plus button at the bottom right!
-
-
-
-{/if}
diff --git a/frontend/src/routes/visited/+page.server.ts b/frontend/src/routes/visited/+page.server.ts
deleted file mode 100644
index 1ff64322..00000000
--- a/frontend/src/routes/visited/+page.server.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { redirect } from '@sveltejs/kit';
-import type { PageServerLoad } from './$types';
-const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
-import type { Adventure } from '$lib/types';
-const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
-
-export const load = (async (event) => {
- if (!event.locals.user) {
- return redirect(302, '/login');
- } else {
- let visitedFetch = await fetch(`${endpoint}/api/adventures/visited/`, {
- headers: {
- Cookie: `${event.cookies.get('auth')}`
- }
- });
- if (!visitedFetch.ok) {
- console.error('Failed to fetch visited adventures');
- return redirect(302, '/login');
- } else {
- let visited = (await visitedFetch.json()) as Adventure[];
- return {
- props: {
- visited
- }
- };
- }
- }
-}) satisfies PageServerLoad;
diff --git a/frontend/src/routes/visited/+page.svelte b/frontend/src/routes/visited/+page.svelte
deleted file mode 100644
index 3a8a8dec..00000000
--- a/frontend/src/routes/visited/+page.svelte
+++ /dev/null
@@ -1,96 +0,0 @@
-
-
-{#if isShowingCreateModal}
- (isShowingCreateModal = false)}
- />
-{/if}
-
-{#if isEditModalOpen}
- (isEditModalOpen = false)}
- on:saveEdit={saveEdit}
- />
-{/if}
-
-
-
-
-
-
-
- Create new...
-
-
-
-
-
-
-
-{#if adventures.length > 0}
- Visited Adventures
-{:else}
-
-{/if}
-
-
- {#each adventures as adventure}
-
- {/each}
-