From e26ab5eea67e1df96e11026a6e182005e61d9a2d Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Thu, 4 Dec 2025 17:39:58 +0500 Subject: [PATCH] sharedda user uchun support list qoshildi --- core/apps/shared/serializers/support.py | 18 +++++++ core/apps/shared/urls.py | 1 + core/apps/shared/views/support.py | 70 ++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/core/apps/shared/serializers/support.py b/core/apps/shared/serializers/support.py index 1f94134..c521b8e 100644 --- a/core/apps/shared/serializers/support.py +++ b/core/apps/shared/serializers/support.py @@ -31,3 +31,21 @@ class SupportCreateSerializer(serializers.Serializer): type=validated_data.get('type'), problem=validated_data.get('problem' ) ) + + +class SupportListSerializer(serializers.ModelSerializer): + district = serializers.SerializerMethodField(method_name='get_district') + + class Meta: + model = Support + fields = [ + 'id', 'problem', 'date', 'type', 'district', 'created_at' + ] + ref_name = "SupportListSerializerForUser" + + def get_district(self, obj): + return { + 'id': obj.district.id, + 'name': obj.district.name, + } if obj.district else None + \ No newline at end of file diff --git a/core/apps/shared/urls.py b/core/apps/shared/urls.py index af1f59f..43c2042 100644 --- a/core/apps/shared/urls.py +++ b/core/apps/shared/urls.py @@ -88,6 +88,7 @@ urlpatterns = [ path('support/', include( [ path('send/', support_view.SupportCreateApiView.as_view(), name='support-create-api'), + path('list/', support_view.SupportListApiView.as_view(), name='support-list-api'), ] )) ] \ No newline at end of file diff --git a/core/apps/shared/views/support.py b/core/apps/shared/views/support.py index a866e03..c56ac86 100644 --- a/core/apps/shared/views/support.py +++ b/core/apps/shared/views/support.py @@ -8,7 +8,7 @@ from drf_yasg.utils import swagger_auto_schema # shared from core.apps.shared.models import Support from core.apps.shared.utils.response_mixin import ResponseMixin -from core.apps.shared.serializers.support import SupportCreateSerializer +from core.apps.shared.serializers.support import SupportCreateSerializer, SupportListSerializer class SupportCreateApiView(generics.GenericAPIView, ResponseMixin): @@ -34,4 +34,72 @@ class SupportCreateApiView(generics.GenericAPIView, ResponseMixin): return self.error_response( data=str(e), message='xatolik, backend dastruchiga murojaat qiling iltimos' + ) + + +class SupportListApiView(generics.GenericAPIView, ResponseMixin): + serializer_class = SupportListSerializer + queryset = Support.objects.all() + permission_classes = [permissions.IsAuthenticated] + + @swagger_auto_schema( + manual_parameters=[ + openapi.Parameter( + in_=openapi.IN_QUERY, + name="problem", + description="problem text bo'yicha filter", + required=False, + type=openapi.TYPE_STRING, + ), + openapi.Parameter( + in_=openapi.IN_QUERY, + name="district", + description="tuman name bo'yicha filter", + required=False, + type=openapi.TYPE_STRING, + ), + openapi.Parameter( + in_=openapi.IN_QUERY, + name="date", + description="date bo'yicha qidirish", + required=False, + type=openapi.FORMAT_DATE, + ), + ], + ) + def get(self, request): + try: + problem = request.query_params.get('problem', None) + district_name = request.query_params.get('district', None) + date = request.query_params.get('date', None) + + queryset = self.queryset.filter(user=request.user) + + # filters + if problem is not None: + queryset = queryset.filter(problem__istartswith=problem) + + if district_name is not None: + queryset = queryset.filter(district__name__istartswith=district_name) + + if date is not None: + queryset = queryset.filter(date=date) + + page = self.paginate_queryset(queryset) + if page is not None: + serializer = self.serializer_class(page, many=True) + return self.success_response( + data=self.get_paginated_response(serializer.data).data, + message="Malumotlar fetch qilindi", + ) + serializer = self.serializer_class(queryset, many=True) + return self.success_response( + data=serializer.data, + message='Malumotlar fetch qilindi' + ) + + except Exception as e: + return self.error_response( + data=str(e), + message='xatolik, iltimos backend dasturchiga murojaat qiling' ) \ No newline at end of file