Document store list query params for swagger; add filter test coverage

Category/neighborhood/search/lat/lng filters on GET /api/v1/stores/
already worked but weren't declared to drf-spectacular, so they never
showed up in swagger.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Ali Asadi 2026-08-19 14:19:48 +03:30
parent 4aacaabdeb
commit 4073081c25
3 changed files with 44 additions and 1 deletions

9
CHANGELOG.md Normal file
View file

@ -0,0 +1,9 @@
# Changelog
## [Unreleased]
### Fixed
- `GET /api/v1/stores/` — documented the `category`, `neighborhood`, `search`, `lat`, and `lng` query params for drf-spectacular so they render in swagger. The filtering itself already worked; only the OpenAPI schema was missing them (`apps/stores/views.py`).
### Added
- Test coverage for `StoreViewSet` list filtering (`apps/stores/tests/test_store_list.py`) — previously untested.

View file

@ -0,0 +1,23 @@
from apps.stores.models import StoreCategory
from apps.orders.tests.base import OrdersTestCase
class StoreListFilterTests(OrdersTestCase):
def test_filter_by_category(self):
other_category = StoreCategory.objects.create(name='رستوران')
self.store2.category = other_category
self.store2.save(update_fields=['category'])
response = self.client.get('/api/v1/stores/', {'category': str(self.store1.category.uuid)})
self.assertEqual(response.status_code, 200)
uuids = {store['uuid'] for store in response.data['results']}
self.assertEqual(uuids, {str(self.store1.uuid)})
def test_no_category_filter_returns_all_stores(self):
response = self.client.get('/api/v1/stores/')
self.assertEqual(response.status_code, 200)
uuids = {store['uuid'] for store in response.data['results']}
self.assertEqual(uuids, {str(self.store1.uuid), str(self.store2.uuid)})

View file

@ -3,7 +3,7 @@ from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D
from django.db.models import Q
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schema_view
from rest_framework import mixins, status, viewsets
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
@ -30,6 +30,17 @@ class StoreCategoryViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
queryset = StoreCategory.objects.all()
@extend_schema_view(
list=extend_schema(
parameters=[
OpenApiParameter('category', str, description='Filter by store category UUID.'),
OpenApiParameter('neighborhood', str, description='Filter by service neighborhood UUID.'),
OpenApiParameter('search', str, description='Search by store name/description.'),
OpenApiParameter('lat', float, description='Latitude; used with `lng` to sort by distance (15km radius).'),
OpenApiParameter('lng', float, description='Longitude; used with `lat` to sort by distance (15km radius).'),
],
),
)
class StoreViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
"""Customer-facing store browsing (home feed, store page)."""