suppurt list api admin uchun chiqarildi
This commit is contained in:
30
core/apps/dashboard/serializers/support.py
Normal file
30
core/apps/dashboard/serializers/support.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# rest framework
|
||||
from rest_framework import serializers
|
||||
|
||||
# shared
|
||||
from core.apps.shared.models import Support
|
||||
|
||||
|
||||
class SupportListSerializer(serializers.ModelSerializer):
|
||||
user = serializers.SerializerMethodField(method_name='get_user')
|
||||
district = serializers.SerializerMethodField(method_name='get_district')
|
||||
|
||||
class Meta:
|
||||
model = Support
|
||||
fields = [
|
||||
'id', 'problem', 'date', 'type', 'district', 'user', 'created_at'
|
||||
]
|
||||
|
||||
def get_district(self, obj):
|
||||
return {
|
||||
'id': obj.district.id,
|
||||
'name': obj.district.name,
|
||||
}
|
||||
|
||||
def get_user(self, obj):
|
||||
return {
|
||||
'id': obj.user.id,
|
||||
'first_name': obj.user.first_name,
|
||||
'last_name': obj.user.last_name,
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ from core.apps.dashboard.views.order import OrderViewSet
|
||||
from core.apps.dashboard.views.payment import PaymentListApiView
|
||||
# location
|
||||
from core.apps.dashboard.views.location import LocationViewSet, UserLocationViewSet
|
||||
# support
|
||||
from core.apps.dashboard.views.support import SupportListApiView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
@@ -66,6 +68,12 @@ urlpatterns = [
|
||||
[
|
||||
path('list/', PaymentListApiView.as_view(), name='payment-list-api'),
|
||||
]
|
||||
)),
|
||||
# -------------- support --------------
|
||||
path('support/', include(
|
||||
[
|
||||
path('list/', SupportListApiView.as_view(), name='support-list-api'),
|
||||
]
|
||||
))
|
||||
]
|
||||
|
||||
|
||||
99
core/apps/dashboard/views/support.py
Normal file
99
core/apps/dashboard/views/support.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# django
|
||||
from django.db.models import Q
|
||||
|
||||
# rest framework
|
||||
from rest_framework import generics, permissions
|
||||
|
||||
# drf yasg
|
||||
from drf_yasg import openapi
|
||||
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
|
||||
|
||||
# dashboard
|
||||
from core.apps.dashboard.serializers.support import SupportListSerializer
|
||||
|
||||
|
||||
class SupportListApiView(generics.GenericAPIView, ResponseMixin):
|
||||
serializer_class = SupportListSerializer
|
||||
queryset = Support.objects.all()
|
||||
permission_classes = [permissions.IsAdminUser]
|
||||
|
||||
@swagger_auto_schema(
|
||||
tags=['Admin Support'],
|
||||
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="user",
|
||||
description="qo'shgan foydalanuvchini ism va familiyasi bo'yicha qidirish",
|
||||
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)
|
||||
user_full_name = request.query_params.get('user', None)
|
||||
|
||||
queryset = self.queryset.all()
|
||||
|
||||
# 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 user_full_name is not None:
|
||||
queryset = queryset.filter(
|
||||
Q(user__first_name__istartswith=user_full_name) |
|
||||
Q(user__last_name__istartswith=user_full_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