diff --git a/backend/server/adventures/models.py b/backend/server/adventures/models.py index e7027cd..4b42725 100644 --- a/backend/server/adventures/models.py +++ b/backend/server/adventures/models.py @@ -105,7 +105,7 @@ class Transportation(models.Model): def clean(self): if self.collection: if self.collection.is_public and not self.is_public: - raise ValidationError('Transportations associated with a public collection must be public. Collection: ' + self.trip.name + ' Transportation: ' + self.name) + raise ValidationError('Transportations associated with a public collection must be public. Collection: ' + self.collection.name + ' Transportation: ' + self.name) if self.user_id != self.collection.user_id: raise ValidationError('Transportations must be associated with collections owned by the same user. Collection owner: ' + self.collection.user_id.username + ' Transportation owner: ' + self.user_id.username) diff --git a/backend/server/adventures/views.py b/backend/server/adventures/views.py index c15bfe0..e658623 100644 --- a/backend/server/adventures/views.py +++ b/backend/server/adventures/views.py @@ -270,26 +270,6 @@ class CollectionViewSet(viewsets.ModelViewSet): def perform_create(self, serializer): serializer.save(user_id=self.request.user) - - # @action(detail=False, methods=['get']) - # def filtered(self, request): - # types = request.query_params.get('types', '').split(',') - # valid_types = ['visited', 'planned'] - # types = [t for t in types if t in valid_types] - - # if not types: - # return Response({"error": "No valid types provided"}, status=400) - - # queryset = Collection.objects.none() - - # for adventure_type in types: - # if adventure_type in ['visited', 'planned']: - # queryset |= Collection.objects.filter( - # type=adventure_type, user_id=request.user.id) - - # queryset = self.apply_sorting(queryset) - # collections = self.paginate_and_respond(queryset, request) - # return collections def paginate_and_respond(self, queryset, request): paginator = self.pagination_class() @@ -300,14 +280,6 @@ class CollectionViewSet(viewsets.ModelViewSet): serializer = self.get_serializer(queryset, many=True) return Response(serializer.data) - # make a view to return all of the associated transportations with a collection - @action(detail=True, methods=['get']) - def transportations(self, request, pk=None): - collection = self.get_object() - transportations = Transportation.objects.filter(collection=collection) - serializer = TransportationSerializer(transportations, many=True) - return Response(serializer.data) - class StatsViewSet(viewsets.ViewSet): permission_classes = [IsAuthenticated] diff --git a/frontend/src/lib/components/EditTransportation.svelte b/frontend/src/lib/components/EditTransportation.svelte new file mode 100644 index 0000000..8dd892c --- /dev/null +++ b/frontend/src/lib/components/EditTransportation.svelte @@ -0,0 +1,184 @@ + + + diff --git a/frontend/src/lib/components/TransportationCard.svelte b/frontend/src/lib/components/TransportationCard.svelte index 1b6df55..8427c8b 100644 --- a/frontend/src/lib/components/TransportationCard.svelte +++ b/frontend/src/lib/components/TransportationCard.svelte @@ -7,36 +7,32 @@ import FileDocumentEdit from '~icons/mdi/file-document-edit'; import { goto } from '$app/navigation'; - import type { Collection } from '$lib/types'; + import type { Collection, Transportation } from '$lib/types'; import { addToast } from '$lib/toasts'; import Plus from '~icons/mdi/plus'; const dispatch = createEventDispatcher(); - export let type: String | undefined | null; + export let transportation: Transportation; - // export let type: String; - - function editAdventure() { - dispatch('edit', collection); + function editTransportation() { + dispatch('edit', transportation); } - export let collection: Collection; - - async function deleteCollection() { - let res = await fetch(`/collections/${collection.id}?/delete`, { - method: 'POST', + async function deleteTransportation() { + let res = await fetch(`/api/transportations/${transportation.id}`, { + method: 'DELETE', headers: { - 'Content-Type': 'application/x-www-form-urlencoded' + 'Content-Type': 'application/json' } }); - if (res.ok) { - console.log('Collection deleted'); - addToast('info', 'Adventure deleted successfully!'); - dispatch('delete', collection.id); + if (!res.ok) { + console.log('Error deleting transportation'); } else { - console.log('Error deleting adventure'); + console.log('Collection deleted'); + addToast('info', 'Transportation deleted successfully!'); + dispatch('delete', transportation.id); } } @@ -45,39 +41,23 @@ class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content" >
{collection.adventures.length} Adventures
- {#if collection.start_date && collection.end_date} -- Dates: {new Date(collection.start_date).toLocaleDateString('en-US', { timeZone: 'UTC' })} - {new Date( - collection.end_date - ).toLocaleDateString('en-US', { timeZone: 'UTC' })} +
+ {transportation.from_location} to {transportation.to_location}
- -- Duration: {Math.floor( - (new Date(collection.end_date).getTime() - new Date(collection.start_date).getTime()) / - (1000 * 60 * 60 * 24) - ) + 1}{' '} - days -
{/if} + {/if} + {#if transportation.date} + {new Date(transportation.date).toLocaleString()} + {/if}