Skip to content

Commit

Permalink
feat: implement global search functionality for adventures, collectio…
Browse files Browse the repository at this point in the history
…ns, users, and locations
  • Loading branch information
seanmorley15 committed Jan 18, 2025
1 parent 9132ef3 commit d60945d
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 209 deletions.
22 changes: 22 additions & 0 deletions backend/server/adventures/managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models
from django.db.models import Q

class AdventureManager(models.Manager):
def retrieve_adventures(self, user, include_owned=False, include_shared=False, include_public=False):
# Initialize the query with an empty Q object
query = Q()

# Add owned adventures to the query if included
if include_owned:
query |= Q(user_id=user.id)

# Add shared adventures to the query if included
if include_shared:
query |= Q(collection__shared_with=user.id)

# Add public adventures to the query if included
if include_public:
query |= Q(is_public=True)

# Perform the query with the final Q object and remove duplicates
return self.filter(query).distinct()
5 changes: 4 additions & 1 deletion backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import uuid
from django.db import models
from django.utils.deconstruct import deconstructible

from adventures.managers import AdventureManager
from django.contrib.auth import get_user_model
from django.contrib.postgres.fields import ArrayField
from django.forms import ValidationError
from django_resized import ResizedImageField


ADVENTURE_TYPES = [
('general', 'General 🌍'),
('outdoor', 'Outdoor 🏞️'),
Expand Down Expand Up @@ -88,6 +89,8 @@ class Adventure(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

objects = AdventureManager()

# DEPRECATED FIELDS - TO BE REMOVED IN FUTURE VERSIONS
# Migrations performed in this version will remove these fields
# image = ResizedImageField(force_format="WEBP", quality=75, null=True, blank=True, upload_to='images/')
Expand Down
1 change: 1 addition & 0 deletions backend/server/adventures/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
router.register(r'categories', CategoryViewSet, basename='categories')
router.register(r'ics-calendar', IcsCalendarGeneratorViewSet, basename='ics-calendar')
router.register(r'overpass', OverpassViewSet, basename='overpass')
router.register(r'search', GlobalSearchView, basename='search')


urlpatterns = [
Expand Down
3 changes: 2 additions & 1 deletion backend/server/adventures/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
from .overpass_view import *
from .reverse_geocode_view import *
from .stats_view import *
from .transportation_view import *
from .transportation_view import *
from .global_search_view import *
4 changes: 0 additions & 4 deletions backend/server/adventures/views/adventure_image_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class AdventureImageViewSet(viewsets.ModelViewSet):
serializer_class = AdventureImageSerializer
permission_classes = [IsAuthenticated]

def dispatch(self, request, *args, **kwargs):
print(f"Method: {request.method}")
return super().dispatch(request, *args, **kwargs)

@action(detail=True, methods=['post'])
def image_delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
Expand Down
Loading

0 comments on commit d60945d

Please sign in to comment.