From e8fb4c1e5b3d84d8a669223acbc033adfef9c361 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Thu, 27 Nov 2025 15:23:05 +0500 Subject: [PATCH] farmaseftika model va api qoshildi --- core/apps/shared/admin/__init__.py | 3 +- core/apps/shared/admin/factory.py | 11 +++ core/apps/shared/migrations/0010_factory.py | 25 +++++++ core/apps/shared/models/__init__.py | 3 +- core/apps/shared/models/factory.py | 13 ++++ core/apps/shared/serializers/factory.py | 14 ++++ core/apps/shared/urls.py | 9 ++- core/apps/shared/views/factory.py | 80 +++++++++++++++++++++ 8 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 core/apps/shared/admin/factory.py create mode 100644 core/apps/shared/migrations/0010_factory.py create mode 100644 core/apps/shared/models/factory.py create mode 100644 core/apps/shared/serializers/factory.py create mode 100644 core/apps/shared/views/factory.py diff --git a/core/apps/shared/admin/__init__.py b/core/apps/shared/admin/__init__.py index 9217bff..310e6d4 100644 --- a/core/apps/shared/admin/__init__.py +++ b/core/apps/shared/admin/__init__.py @@ -5,4 +5,5 @@ from .pharmacy import * from .doctor import * from .plan import * from .tour_plan import * -from .location import * \ No newline at end of file +from .location import * +from .factory import * \ No newline at end of file diff --git a/core/apps/shared/admin/factory.py b/core/apps/shared/admin/factory.py new file mode 100644 index 0000000..d67b28a --- /dev/null +++ b/core/apps/shared/admin/factory.py @@ -0,0 +1,11 @@ +from django.contrib import admin + + +# shared +from core.apps.shared.models import Factory + + + +@admin.register(Factory) +class FactoryAdmin(admin.ModelAdmin): + list_display = ['id', 'name'] \ No newline at end of file diff --git a/core/apps/shared/migrations/0010_factory.py b/core/apps/shared/migrations/0010_factory.py new file mode 100644 index 0000000..4d0abbd --- /dev/null +++ b/core/apps/shared/migrations/0010_factory.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2 on 2025-11-27 10:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shared', '0009_remove_tourplan_district_tourplan_location_send_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='Factory', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=200)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/core/apps/shared/models/__init__.py b/core/apps/shared/models/__init__.py index ca4d702..99e277b 100644 --- a/core/apps/shared/models/__init__.py +++ b/core/apps/shared/models/__init__.py @@ -6,4 +6,5 @@ from .doctor import * from .pharmacy import * from .plan import * from .location import * -from .tour_plan import * \ No newline at end of file +from .tour_plan import * +from .factory import * diff --git a/core/apps/shared/models/factory.py b/core/apps/shared/models/factory.py new file mode 100644 index 0000000..6cde1e2 --- /dev/null +++ b/core/apps/shared/models/factory.py @@ -0,0 +1,13 @@ +from django.db import models + +# shared +from core.apps.shared.models import BaseModel + + +class Factory(BaseModel): + name = models.CharField(max_length=200) + + def __str__(self): + return self.name + + \ No newline at end of file diff --git a/core/apps/shared/serializers/factory.py b/core/apps/shared/serializers/factory.py new file mode 100644 index 0000000..6d17c6b --- /dev/null +++ b/core/apps/shared/serializers/factory.py @@ -0,0 +1,14 @@ +from rest_framework import serializers + + +# shared +from core.apps.shared.models import Factory + + + +class FactorySerializer(serializers.ModelSerializer): + class Meta: + model = Factory + fields = [ + 'id', 'name', 'created_at' + ] \ No newline at end of file diff --git a/core/apps/shared/urls.py b/core/apps/shared/urls.py index 3dbdeb3..61f236c 100644 --- a/core/apps/shared/urls.py +++ b/core/apps/shared/urls.py @@ -16,6 +16,8 @@ from core.apps.shared.views import plan as plan_view from core.apps.shared.views import location as location_view # shared tour plan view from core.apps.shared.views import tour_plan as tp_view +# shared factory view +from core.apps.shared.views import factory as factory_view urlpatterns = [ @@ -74,5 +76,10 @@ urlpatterns = [ [ path('list/', tp_view.TourPlanListApiView.as_view(), name='tour-plan-list-api'), ] - )) + )), + path('factory/', include( + [ + path('list/', factory_view.FactoryListApiView.as_view(), name='factory-list-api'), + ], + )), ] \ No newline at end of file diff --git a/core/apps/shared/views/factory.py b/core/apps/shared/views/factory.py new file mode 100644 index 0000000..d1e8bf4 --- /dev/null +++ b/core/apps/shared/views/factory.py @@ -0,0 +1,80 @@ +# 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 Factory +from core.apps.shared.utils.response_mixin import ResponseMixin +from core.apps.shared.serializers.factory import FactorySerializer + + +class FactoryListApiView(generics.GenericAPIView, ResponseMixin): + serializer_class = FactorySerializer + queryset = Factory.objects.all() + permission_classes = [permissions.IsAuthenticated] + + @swagger_auto_schema( + tags=["Farmaseftika"], + operation_description='Farmasevtikani listini olish uchun api', + manual_parameters=[ + openapi.Parameter( + name='search', + in_=openapi.IN_QUERY, + description='Nomi boyicha qidirish', + type=openapi.TYPE_STRING, + required=False, + ) + ], + responses={ + 200: openapi.Response( + schema=None, + description='Success', + examples={ + "application/json": { + "status_code": 200, + "status": "success", + "message": "malumotlar fetch qilindi", + "data": [ + { + "id": 0, + "name": "string", + "created_at": "string", + } + ] + } + } + ), + 500: openapi.Response( + schema=None, + description="Server Error", + examples={ + "application/json": { + "status_code": 500, + "status": "success", + "message": "xatolik", + "data": "string", + } + } + ), + } + ) + def get(self, request): + try: + query = self.queryset.order_by('-created_at') + search = request.query_params.get('search') + if search: + query = query.filter(name__istartswith=search) + + serializer = self.serializer_class(query, 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' + )