Skip to content

Commit

Permalink
Merge pull request #327 from seanmorley15/development
Browse files Browse the repository at this point in the history
fixed
  • Loading branch information
seanmorley15 authored Oct 7, 2024
2 parents 30d1bd1 + 7d9bc16 commit eaeff3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
28 changes: 10 additions & 18 deletions backend/server/adventures/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ def to_representation(self, instance):
public_url = public_url.replace("'", "")
representation['image'] = f"{public_url}/media/{instance.image.name}"
return representation



class VisitSerializer(serializers.ModelSerializer):
class Meta:
model = Visit
fields = ['id', 'start_date', 'end_date', 'notes']
read_only_fields = ['id']

class AdventureSerializer(serializers.ModelSerializer):
images = AdventureImageSerializer(many=True, read_only=True)
visits = VisitSerializer(many=True, read_only=False)
class Meta:
model = Adventure
fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude']
fields = ['id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location', 'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'type', 'longitude', 'latitude', 'visits']
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']

def to_representation(self, instance):
Expand Down Expand Up @@ -70,7 +75,7 @@ def update(self, instance, validated_data):
instance.visits.filter(id__in=visits_to_delete).delete()

return instance

class TransportationSerializer(serializers.ModelSerializer):

class Meta:
Expand Down Expand Up @@ -99,17 +104,7 @@ class Meta:
'id', 'user_id', 'name', 'is_checked', 'checklist', 'created_at', 'updated_at'
]
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id', 'checklist']

# def validate(self, data):
# # Check if the checklist is public and the checklist item is not
# checklist = data.get('checklist')
# is_checked = data.get('is_checked', False)
# if checklist and checklist.is_public and not is_checked:
# raise serializers.ValidationError(
# 'Checklist items associated with a public checklist must be checked.'
# )



class ChecklistSerializer(serializers.ModelSerializer):
items = ChecklistItemSerializer(many=True, source='checklistitem_set')
class Meta:
Expand Down Expand Up @@ -173,9 +168,6 @@ def validate(self, data):

return data




class CollectionSerializer(serializers.ModelSerializer):
adventures = AdventureSerializer(many=True, read_only=True, source='adventure_set')
transportations = TransportationSerializer(many=True, read_only=True, source='transportation_set')
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,11 @@ export function isAdventureVisited(adventure: Adventure) {
const currentTime = Date.now();

// Check if any visit's start_date is before the current time.
return adventure.visits.some((visit) => {
const visitStartTime = new Date(visit.start_date).getTime();
return visit.start_date && visitStartTime <= currentTime;
});
return (
adventure.visits &&
adventure.visits.some((visit) => {
const visitStartTime = new Date(visit.start_date).getTime();
return visit.start_date && visitStartTime <= currentTime;
})
);
}

0 comments on commit eaeff3c

Please sign in to comment.