search page without from-to
This commit is contained in:
0
backend/api/search/__init__.py
Normal file
0
backend/api/search/__init__.py
Normal file
10
backend/api/search/serializers.py
Normal file
10
backend/api/search/serializers.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from api.main.serializers import HomePageRouteSerializer
|
||||
from routes.models import Route
|
||||
|
||||
|
||||
class SearchRouteSerializer(HomePageRouteSerializer):
|
||||
class Meta(HomePageRouteSerializer.Meta):
|
||||
model = Route
|
||||
fields = HomePageRouteSerializer.Meta.fields
|
||||
|
||||
|
||||
24
backend/api/search/views.py
Normal file
24
backend/api/search/views.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from rest_framework import generics
|
||||
from routes.models import Route
|
||||
from .serializers import SearchRouteSerializer
|
||||
from api.utils.pagination import StandardResultsSetPagination
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from routes.constants.routeChoices import owner_type_choices
|
||||
|
||||
|
||||
class SearchRouteListView(generics.ListAPIView):
|
||||
serializer_class = SearchRouteSerializer
|
||||
pagination_class = StandardResultsSetPagination
|
||||
|
||||
def get_queryset(self):
|
||||
owner_type = self.kwargs.get('owner_type')
|
||||
valid_types = [choice[0] for choice in owner_type_choices]
|
||||
|
||||
if not owner_type or owner_type not in valid_types:
|
||||
raise ValidationError("Invalid or missing owner_type. Must be either 'customer' or 'mover'")
|
||||
|
||||
queryset = Route.objects.filter(
|
||||
owner_type=owner_type
|
||||
).order_by('-arrival_DT')
|
||||
|
||||
return queryset
|
||||
@@ -16,6 +16,8 @@ CountryView,
|
||||
GetMembershipData,
|
||||
ChangeUserMembership)
|
||||
|
||||
from api.search.views import SearchRouteListView
|
||||
|
||||
urlpatterns = [
|
||||
path("v1/faq/", FAQView.as_view(), name='faqMain'),
|
||||
path("v1/news/", NewsView.as_view(), name="newsmain"),
|
||||
@@ -38,4 +40,6 @@ urlpatterns = [
|
||||
|
||||
path("v1/plans/", GetMembershipData.as_view({'get':'get_pricing_data'}), name='get_pricing_data'),
|
||||
path("v1/account/change_membership/", ChangeUserMembership.as_view({'patch':'change_plan'}), name='change_plan'),
|
||||
|
||||
path('v1/search/<str:owner_type>/', SearchRouteListView.as_view(), name='search-routes'),
|
||||
]
|
||||
6
backend/api/utils/pagination.py
Normal file
6
backend/api/utils/pagination.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
class StandardResultsSetPagination(PageNumberPagination):
|
||||
page_size = 25
|
||||
page_size_query_param = 'page_size'
|
||||
max_page_size = 25
|
||||
Reference in New Issue
Block a user