shiforkorlar royxatini olish uchun api qoshildi

This commit is contained in:
behruz-dev
2025-11-28 15:23:02 +05:00
parent e2386dcb11
commit 120b5ea4d5
4 changed files with 230 additions and 2 deletions

View File

@@ -1,10 +1,16 @@
# django
from django.urls import path, include
# rest framework
from rest_framework.routers import DefaultRouter
### dashboard ###
# users
from core.apps.dashboard.views import user as user_views
# district
from core.apps.dashboard.views import district as district_views
# doctor
from core.apps.dashboard.views.doctor import DoctorViewSet
urlpatterns = [
@@ -28,3 +34,10 @@ urlpatterns = [
)),
]
### ViewSets ###
router = DefaultRouter()
router.register("doctor", DoctorViewSet)
urlpatterns += router.urls

View File

@@ -0,0 +1,197 @@
# django
from django.shortcuts import get_object_or_404
from django.db.models import Q
# rest framework
from rest_framework import viewsets, permissions
from rest_framework.decorators import action
# drf yasg
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
# dashboard
from core.apps.dashboard.serializers import doctor as serializers
# shared
from core.apps.shared.models import Doctor
from core.apps.shared.utils.response_mixin import ResponseMixin
class DoctorViewSet(viewsets.GenericViewSet, ResponseMixin):
permission_classes = [permissions.IsAdminUser]
queryset = Doctor.objects.all()
def get_serializer_class(self):
if self.action == "POST":
return serializers.DoctorCreateSerializer
elif self.action in ("PATCH", "PUT"):
return serializers.DoctorUpdateSerializer
else:
return serializers.DoctorListSerializer
@swagger_auto_schema(
tags=['Admin Doctors'],
manual_parameters=[
openapi.Parameter(
in_=openapi.IN_QUERY,
name="full_name",
description="shiforkor ism va familiyasi bo'yicha qidirish",
required=False,
type=openapi.TYPE_STRING,
),
openapi.Parameter(
in_=openapi.IN_QUERY,
name="district_name",
description="tuman nomi bo'yicha qidirish",
required=False,
type=openapi.TYPE_STRING,
),
openapi.Parameter(
in_=openapi.IN_QUERY,
name="place_name",
description="obyekt bo'yicha qidirish",
required=False,
type=openapi.TYPE_STRING,
),
openapi.Parameter(
in_=openapi.IN_QUERY,
name="work_place",
description="ish joyi bo'yicha qidirish",
required=False,
type=openapi.TYPE_STRING,
),
openapi.Parameter(
in_=openapi.IN_QUERY,
name="sphere",
description="lavozimi bo'yicha qidirish",
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,
),
],
operation_description="Shifokorlar ro'yxatini olish",
operation_summary="Shifokolar ro'yxati",
responses={
200: openapi.Response(
schema=None,
description="Success",
examples={
"application/json": {
"status_code": 200,
"status": "success",
"message": "malumotlar fetch qilindi",
"data": {
"count": 0,
"next": "string",
"pervious": "string",
"response": [
{
"id": 0,
"first_name": "string",
"last_name": "string",
"phone_number": "string",
"work_place": "string",
"sphere": "string",
"description": "string",
"district": {
"id": 0,
"name": "string",
},
"place": {
"id": 0,
"name": "string"
},
"user": {
'id': 0,
'first_name': "string",
'last_name': "string",
},
"longitude": 0.0,
"latitude": 0.0,
"extra_location": {},
"created_at": "string"
}
]
}
}
}
),
500: openapi.Response(
schema=None,
description="Server Error",
examples={
"application/json": {
"status_code": 500,
"success": "error",
"message": "xatolik",
"data": "string"
}
}
)
}
)
@action(detail=False, methods=['get'], url_path="list")
def get(self, request):
try:
# params
full_name = request.query_params.get('full_name', None)
district_name = request.query_params.get('district_name', None)
place_name = request.query_params.get('place_name', None)
work_place = request.query_params.get('work_place', None)
sphere = request.query_params.get('sphere', None)
user_full_name = request.query_params.get('user', None)
queryset = self.queryset.all()
# filters
if full_name is not None:
queryset = queryset.filter(
Q(first_name__istartswith=full_name) |
Q(last_name__istartswith=full_name)
)
if district_name is not None:
queryset = queryset.filter(
district__name__istartswith=district_name
)
if place_name is not None:
queryset = queryset.filter(
place__name__istartswith=place_name
)
if work_place is not None:
queryset = queryset.filter(
work_place__istartswith=work_place
)
if sphere is not None:
queryset = queryset.filter(
sphere__istartswith=sphere
)
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)
)
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.success_response(
data=self.get_paginated_response(serializer.data).data,
message='malumotlar fetch qilindi'
)
serializer = self.get_serializer(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"
)

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2 on 2025-11-28 10:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('shared', '0011_tourplan_date'),
]
operations = [
migrations.AlterField(
model_name='doctor',
name='extra_location',
field=models.JSONField(blank=True, null=True),
),
]

View File

@@ -21,7 +21,7 @@ class Doctor(BaseModel):
# location
longitude = models.FloatField(default=0.00)
latitude = models.FloatField(default=0.00)
extra_location = models.JSONField()
extra_location = models.JSONField(null=True, blank=True)
def __str__(self):
return f"{self.first_name} {self.last_name} - {self.work_place}"