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