From 120b5ea4d5c4b906cf796edd703e5a5c5799e5d4 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Fri, 28 Nov 2025 15:23:02 +0500 Subject: [PATCH] shiforkorlar royxatini olish uchun api qoshildi --- core/apps/dashboard/urls.py | 15 +- core/apps/dashboard/views/doctor.py | 197 ++++++++++++++++++ .../0012_alter_doctor_extra_location.py | 18 ++ core/apps/shared/models/doctor.py | 2 +- 4 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 core/apps/dashboard/views/doctor.py create mode 100644 core/apps/shared/migrations/0012_alter_doctor_extra_location.py diff --git a/core/apps/dashboard/urls.py b/core/apps/dashboard/urls.py index 30f5779..f92e64c 100644 --- a/core/apps/dashboard/urls.py +++ b/core/apps/dashboard/urls.py @@ -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 = [ @@ -27,4 +33,11 @@ urlpatterns = [ ] )), -] \ No newline at end of file +] + + +### ViewSets ### +router = DefaultRouter() +router.register("doctor", DoctorViewSet) + +urlpatterns += router.urls \ No newline at end of file diff --git a/core/apps/dashboard/views/doctor.py b/core/apps/dashboard/views/doctor.py new file mode 100644 index 0000000..2c9507c --- /dev/null +++ b/core/apps/dashboard/views/doctor.py @@ -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" + ) diff --git a/core/apps/shared/migrations/0012_alter_doctor_extra_location.py b/core/apps/shared/migrations/0012_alter_doctor_extra_location.py new file mode 100644 index 0000000..66928cd --- /dev/null +++ b/core/apps/shared/migrations/0012_alter_doctor_extra_location.py @@ -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), + ), + ] diff --git a/core/apps/shared/models/doctor.py b/core/apps/shared/models/doctor.py index 4b7063d..070f64b 100644 --- a/core/apps/shared/models/doctor.py +++ b/core/apps/shared/models/doctor.py @@ -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}"