Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Added timestamp filter to areas endpoint and changed filter name #139

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions applications/feeds/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from feeds.serializers import LocationFilterParamSerializer


class LocationFilterBackend(filters.BaseFilterBackend):
class TimestampFilterBackend(filters.BaseFilterBackend):
"""
Filter that only allows users to see their own objects.
Filter for timestamp filter.
"""

def filter_queryset(self, request, queryset, view):
params = LocationFilterParamSerializer(data=request.query_params)
params = TimestampFilterParamSerializer(data=request.query_params)
params.is_valid(raise_exception=True)
filter_list = params.validated_data
timestamp__gte = filter_list.get("raw__timestamp__gte", None)
Expand Down
2 changes: 1 addition & 1 deletion applications/feeds/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
fields = ["id", "formatted_address", "loc", "viewport", "raw"]


class LocationFilterParamSerializer(serializers.Serializer):
class TimestampFilterParamSerializer(serializers.Serializer):
"""
Filter by query param: timestamp
"""
Expand Down
4 changes: 3 additions & 1 deletion applications/feeds/views/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

# Applications
from feeds.models import Location
from feeds.views.base import BaseAreaViewSet
from feeds.views import BaseAreaViewSet
from feeds.serializers import LocationSerializer, LocationLiteSerializer
from feeds.filters import TimestampFilterBackend


class AreaViewSet(BaseAreaViewSet):
serializer_class = LocationSerializer
filter_backends = [TimestampFilterBackend]


class AreaLiteViewSet(BaseAreaViewSet):
Expand Down
4 changes: 2 additions & 2 deletions applications/feeds/views/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Applications
from feeds.models import Location
from core.pagination import LocationPagination
from feeds.filters import LocationFilterBackend
from feeds.filters import TimestampFilterBackend
from feeds.serializers import LocationSerializer


Expand All @@ -13,4 +13,4 @@ class LocationViewSet(ModelViewSet):
serializer_class = LocationSerializer
http_method_names = ["options", "head", "get"]
pagination_class = LocationPagination
filter_backends = [LocationFilterBackend]
filter_backends = [TimestampFilterBackend]
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ services:
- POSTGRES_PORT=5432
command:
- /start-django
depends_on:
- database
restart: always

database:
image: postgres:15.1
Expand Down