winofy-backend/apps/reviews/views.py
Ali Asadi 52adc732fa Initial Winofy backend: marketplace core (no payment integration)
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>
2026-08-10 14:03:15 +03:30

50 lines
1.9 KiB
Python

from rest_framework import mixins, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from apps.core.permissions import IsStoreOwner
from .models import Review
from .serializers import ReviewSerializer, SellerReplySerializer
class ReviewViewSet(mixins.ListModelMixin, mixins.CreateModelMixin, viewsets.GenericViewSet):
"""Customer reviews — create after a delivered order, list is public per store."""
schema_tags = ['Reviews']
serializer_class = ReviewSerializer
def get_permissions(self):
if self.action == 'create':
return [IsAuthenticated()]
return [AllowAny()]
def get_queryset(self):
queryset = Review.objects.select_related('customer', 'store')
store_uuid = self.request.query_params.get('store')
if store_uuid:
queryset = queryset.filter(store__uuid=store_uuid)
return queryset
class SellerReviewViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
"""Reviews left for the authenticated seller's store, with reply support."""
schema_tags = ['Seller · Reviews']
permission_classes = [IsAuthenticated, IsStoreOwner]
serializer_class = ReviewSerializer
def get_queryset(self):
if getattr(self, 'swagger_fake_view', False):
return Review.objects.none()
return Review.objects.filter(store=self.request.user.store).select_related('customer')
@action(detail=True, methods=['post'])
def reply(self, request, pk=None):
review = self.get_object()
serializer = SellerReplySerializer(data=request.data)
serializer.is_valid(raise_exception=True)
review.seller_reply = serializer.validated_data['seller_reply']
review.save(update_fields=['seller_reply', 'updated_at'])
return Response(ReviewSerializer(review).data)