From 4fa754012d299e88d4f0bd4b2eaf262a20b23e2a Mon Sep 17 00:00:00 2001 From: Fazliddin Abdurahimov Date: Thu, 7 Aug 2025 17:06:37 +0500 Subject: [PATCH] fix: added serializer_class to views needed --- core/apps/accounts/models/user.py | 1 - core/apps/companies/urls.py | 4 ++-- core/apps/companies/views/accounts.py | 2 +- core/apps/companies/views/companies.py | 14 ++++++++++---- core/apps/companies/views/folders.py | 3 ++- .../serializers/contracts/contracts.py | 17 +++++++++++++++++ core/apps/contracts/views/owners.py | 1 + docs/ENDPOINTS.md | 1 - 8 files changed, 33 insertions(+), 10 deletions(-) diff --git a/core/apps/accounts/models/user.py b/core/apps/accounts/models/user.py index 8be5125..289773d 100644 --- a/core/apps/accounts/models/user.py +++ b/core/apps/accounts/models/user.py @@ -64,7 +64,6 @@ class User(auth_models.AbstractUser): _("Email Address"), blank=True, ) - role = models.CharField( _("Role"), max_length=255, diff --git a/core/apps/companies/urls.py b/core/apps/companies/urls.py index 18f5daa..1b8796d 100644 --- a/core/apps/companies/urls.py +++ b/core/apps/companies/urls.py @@ -5,8 +5,8 @@ from . import views router = DefaultRouter() -router.register(r"company-accounts", views.CompanyAccountCrudViewSet, "company-account-view-set") # type: ignore -router.register(r"company-folders", views.CompanyFolderCrudViewSet, "company-folders-view-set") # type: ignore +router.register(r"company-accounts", views.CompanyAccountViewSet, "company-account-view-set") # type: ignore +router.register(r"company-folders", views.CompanyFolderViewSet, "company-folders-view-set") # type: ignore router.register(r"companies", views.CompanyCrudViewSet, "companies-view-set") # type: ignore diff --git a/core/apps/companies/views/accounts.py b/core/apps/companies/views/accounts.py index 1d36741..eecff1f 100644 --- a/core/apps/companies/views/accounts.py +++ b/core/apps/companies/views/accounts.py @@ -16,7 +16,7 @@ from core.apps.companies.serializers.accounts import ( # @view-set | ALL - /company-accounts ################################################################################### @extend_schema(tags=["Company Accounts"]) -class CompanyAccountCrudViewSet(BaseViewSetMixin, ModelViewSet): +class CompanyAccountViewSet(BaseViewSetMixin, ModelViewSet): queryset = CompanyAccountModel.objects.all() serializer_class = ListCompanyAccountSerializer permission_classes = [AllowAny] diff --git a/core/apps/companies/views/companies.py b/core/apps/companies/views/companies.py index 7188d46..a529373 100644 --- a/core/apps/companies/views/companies.py +++ b/core/apps/companies/views/companies.py @@ -28,6 +28,7 @@ from core.apps.companies.serializers import ( from core.apps.contracts.serializers import ( RetrieveContractSerializer, BaseContractSerializer, + RetrieveContractQuerySerializer, ) from core.apps.contracts.models import ContractModel @@ -79,7 +80,8 @@ class CompanyContractApiView(BaseApiViewMixin, GenericAPIView): # type: ignore #! TODO: status should be added. @extend_schema( summary="Company Contracts", - description="Get List Company Contracts" + description="Get List Company Contracts", + parameters=[RetrieveContractQuerySerializer] ) def get( self, @@ -88,9 +90,13 @@ class CompanyContractApiView(BaseApiViewMixin, GenericAPIView): # type: ignore **kwargs: object, ) -> Response: company = self.get_object() - contracts = ContractModel.objects.filter( - owners__legal_entity__phone=company.phone, - ).distinct() + contracts = ( + ContractModel.objects.filter( + owners__legal_entity__phone=company.phone, + ) + .select_related("owners") + .distinct() + ) folders_param = request.data.get("folders") if folders_param: diff --git a/core/apps/companies/views/folders.py b/core/apps/companies/views/folders.py index db1e647..56ca587 100644 --- a/core/apps/companies/views/folders.py +++ b/core/apps/companies/views/folders.py @@ -28,8 +28,9 @@ from core.apps.companies.serializers.folders import ( # @view-set | ALL - /company-folders ################################################################################### @extend_schema(tags=["Company Folders"]) -class CompanyFolderCrudViewSet(BaseViewSetMixin, ModelViewSet): +class CompanyFolderViewSet(BaseViewSetMixin, ModelViewSet): queryset = CompanyFolderModel.objects.all() + serializer_class = ListCompanyFolderSerializer permission_classes = [AllowAny] action_permission_classes = { # type: ignore diff --git a/core/apps/contracts/serializers/contracts/contracts.py b/core/apps/contracts/serializers/contracts/contracts.py index 2abacaf..5bfc705 100644 --- a/core/apps/contracts/serializers/contracts/contracts.py +++ b/core/apps/contracts/serializers/contracts/contracts.py @@ -154,3 +154,20 @@ class CreateContractSerializer(BaseContractSerializer): attached_files.save() # type: ignore return contract + + +########################################################### +# Query Serializers +########################################################### +class RetrieveContractQuerySerializer(serializers.Serializer): + folders = serializers.ListField( + child=serializers.CharField(), + required=False, + help_text="Company Folders that contract should be allocated to." + ) + status = serializers.ListField( + child=serializers.CharField(), + required=False, + help_text="Contract Status which contract have related to current owner." + ) + only_my_contracts = serializers.BooleanField(default=False) diff --git a/core/apps/contracts/views/owners.py b/core/apps/contracts/views/owners.py index c2e6421..6c7a3eb 100644 --- a/core/apps/contracts/views/owners.py +++ b/core/apps/contracts/views/owners.py @@ -61,6 +61,7 @@ class ContractOwnerViewSet(BaseViewSetMixin, ModelViewSet): @extend_schema(tags=["Contract Files"]) class ContractOwnerAttachedFileApiView(BaseApiViewMixin, GenericAPIView): # type: ignore permission_classes = [AllowAny] + serializer_class = ListContractOwnerSerializer queryset = ContractOwnerModel.objects.all() method_permission_classes = {"delete": [AllowAny]} diff --git a/docs/ENDPOINTS.md b/docs/ENDPOINTS.md index f47f927..af9e810 100644 --- a/docs/ENDPOINTS.md +++ b/docs/ENDPOINTS.md @@ -68,7 +68,6 @@ Testers will write `done`, `not ok` and developers will define status that is no * `PATCH /company-accounts/` — admin — ok * `DELETE /company-accounts/` — admin — ok * `POST /accounts/verify` — user — TODO - * required: `phone`, `code` ---