sharedda user uchun support list qoshildi
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
]
|
||||
))
|
||||
]
|
||||
@@ -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):
|
||||
@@ -35,3 +35,71 @@ class SupportCreateApiView(generics.GenericAPIView, ResponseMixin):
|
||||
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'
|
||||
)
|
||||
Reference in New Issue
Block a user