Skip to content
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
2 changes: 1 addition & 1 deletion src/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
path("me/", MeView.as_view(), name="me"),
path("rides/<int:id>/", RideView.as_view(), name="ride"),
path("rides/", RidesView.as_view(), name="rides"),
path("search/", SearchView.as_view(), name="search"),
path("search/depart/<str:depart>/daysbefore/<int:daysbefore>/daysafter/<int:daysafter>/start/<str:start>/end/<str:end>/radius/<int:radius>/", SearchView.as_view(), name="search"),
re_path(r"^requests/", include("request.urls")),
re_path(r"^prompts/", include("prompts.urls"))
]
10 changes: 6 additions & 4 deletions src/ride/controllers/search_ride_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def __init__(self, data, request, serializer):

def process(self):
departure_datetime = self._data.get("departure_datetime")
days_before = self._data.get("days_before")
days_after = self._data.get("days_after")
start_location_place_id = self._data.get("start_location_place_id")
end_location_place_id = self._data.get("end_location_place_id")
radius = self._data.get("radius")
Expand Down Expand Up @@ -67,13 +69,13 @@ def process(self):
departure_datetime
).astimezone(tz)

departure_last_week = departure_datetime_object - datetime.timedelta(days=7)
departure_next_week = departure_datetime_object + datetime.timedelta(days=7)
departure_before = departure_datetime_object - datetime.timedelta(days=days_before)
departure_after = departure_datetime_object + datetime.timedelta(days=days_after)

all_rides = Ride.objects.filter(
path__in=paths,
departure_datetime__gte=departure_last_week,
departure_datetime__lte=departure_next_week,
departure_datetime__gte=departure_before,
departure_datetime__lte=departure_after,
)

# Sort results based on location and time proximity
Expand Down
18 changes: 11 additions & 7 deletions src/ride/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ def delete(self, request, id):
class SearchView(generics.GenericAPIView):
serializer_class = RideSerializer
permission_classes = api_settings.CONSUMER_PERMISSIONS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we get rid of these permission classes?

lookup_fields = ['depart', 'daysbefore', 'daysafter', 'start', 'end', 'radius']

def post(self, request):
def get(self, request, depart, daysbefore, daysafter, start, end, radius):
"""Search for a ride."""
try:
data = json.loads(request.body)
except json.JSONDecodeError:
data = request.data

return SearchRideController(data, request, self.serializer_class).process()
data = {
"departure_datetime": depart,
"days_before": daysbefore,
"days_after": daysafter,
"start_location_place_id": start,
"end_location_place_id": end,
"radius": radius
}
return SearchRideController(data, self.serializer_class).process()