Django 6 + DRF resource server against the Gooyal accounts OAuth2 service, matching the Winsoo ecosystem's conventions. Covers locations, stores, catalog, cart, checkout/orders (with the multi-store-cart split and the status stepper), reviews, and notifications, plus a demo-data seed command. Payment integration (wallet debits, online gateway, seller payouts) is intentionally left out here — see feature/payment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
from rest_framework import mixins, viewsets
|
|
from rest_framework.permissions import AllowAny, IsAuthenticated
|
|
|
|
from .models import Address, City, Neighborhood
|
|
from .serializers import AddressSerializer, CitySerializer, NeighborhoodSerializer
|
|
|
|
|
|
class CityViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
|
|
schema_tags = ['Locations']
|
|
permission_classes = [AllowAny]
|
|
serializer_class = CitySerializer
|
|
queryset = City.objects.filter(is_active=True)
|
|
|
|
|
|
class NeighborhoodViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
|
|
schema_tags = ['Locations']
|
|
permission_classes = [AllowAny]
|
|
serializer_class = NeighborhoodSerializer
|
|
queryset = Neighborhood.objects.filter(is_active=True).select_related('city')
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
city_uuid = self.request.query_params.get('city')
|
|
if city_uuid:
|
|
queryset = queryset.filter(city__uuid=city_uuid)
|
|
return queryset
|
|
|
|
|
|
class AddressViewSet(viewsets.ModelViewSet):
|
|
schema_tags = ['Addresses']
|
|
permission_classes = [IsAuthenticated]
|
|
serializer_class = AddressSerializer
|
|
|
|
def get_queryset(self):
|
|
if getattr(self, 'swagger_fake_view', False):
|
|
return Address.objects.none()
|
|
return Address.objects.filter(user=self.request.user).select_related('city', 'neighborhood')
|