add/fix: company-folders/{id}/contracts changes
This commit is contained in:
@@ -26,5 +26,10 @@ urlpatterns: list[object] = [
|
|||||||
r"companies/<uuid:pk>/accounts",
|
r"companies/<uuid:pk>/accounts",
|
||||||
views.CompanyAccountApiView.as_view(),
|
views.CompanyAccountApiView.as_view(),
|
||||||
name="company-accounts-api-view"
|
name="company-accounts-api-view"
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
r"company-folders/<uuid:pk>/contracts",
|
||||||
|
views.ContractFolderApiView.as_view(),
|
||||||
|
name="company-folders-api-view"
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -5,20 +5,15 @@ from drf_spectacular.utils import extend_schema
|
|||||||
|
|
||||||
from rest_framework.decorators import action # type: ignore
|
from rest_framework.decorators import action # type: ignore
|
||||||
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
||||||
from rest_framework.viewsets import ModelViewSet, GenericViewSet # type: ignore
|
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||||
from rest_framework.generics import GenericAPIView # type: ignore
|
from rest_framework.generics import GenericAPIView # type: ignore
|
||||||
from rest_framework.request import HttpRequest # type: ignore
|
from rest_framework.request import HttpRequest # type: ignore
|
||||||
from rest_framework.response import Response # type: ignore
|
from rest_framework.response import Response # type: ignore
|
||||||
from rest_framework import status # type: ignore
|
from rest_framework import status # type: ignore
|
||||||
from rest_framework.generics import get_object_or_404 # type: ignore
|
|
||||||
|
|
||||||
from core.utils.views import BaseApiViewMixin
|
from core.utils.views import BaseApiViewMixin
|
||||||
from core.apps.companies.permissions import IsCompanyAccount
|
from core.apps.companies.permissions import IsCompanyAccount
|
||||||
from core.apps.companies.models import (
|
from core.apps.companies.models import CompanyModel, CompanyFolderModel, CompanyAccountModel
|
||||||
CompanyModel,
|
|
||||||
CompanyFolderModel,
|
|
||||||
CompanyAccountModel,
|
|
||||||
)
|
|
||||||
from core.apps.companies.serializers import (
|
from core.apps.companies.serializers import (
|
||||||
CreateCompanySerializer,
|
CreateCompanySerializer,
|
||||||
ListCompanySerializer,
|
ListCompanySerializer,
|
||||||
@@ -34,7 +29,7 @@ from core.apps.companies.serializers import (
|
|||||||
|
|
||||||
from core.apps.contracts.serializers import (
|
from core.apps.contracts.serializers import (
|
||||||
RetrieveContractSerializer,
|
RetrieveContractSerializer,
|
||||||
BaseContractSerializer
|
BaseContractSerializer,
|
||||||
)
|
)
|
||||||
|
|
||||||
from core.apps.contracts.models import ContractModel
|
from core.apps.contracts.models import ContractModel
|
||||||
|
|||||||
@@ -5,14 +5,15 @@ from django.db import transaction
|
|||||||
from drf_spectacular.utils import extend_schema
|
from drf_spectacular.utils import extend_schema
|
||||||
from rest_framework.decorators import action # type: ignore
|
from rest_framework.decorators import action # type: ignore
|
||||||
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
from rest_framework.permissions import AllowAny, IsAdminUser # type: ignore
|
||||||
from rest_framework.viewsets import ModelViewSet, GenericViewSet # type: ignore
|
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||||
from rest_framework.generics import GenericAPIView # type: ignore
|
from rest_framework.generics import GenericAPIView # type: ignore
|
||||||
from rest_framework.request import HttpRequest # type: ignore
|
from rest_framework.request import HttpRequest # type: ignore
|
||||||
from rest_framework.response import Response # type: ignore
|
from rest_framework.response import Response # type: ignore
|
||||||
from rest_framework import status # type: ignore
|
from rest_framework import status # type: ignore
|
||||||
|
|
||||||
from core.apps.contracts.serializers.contracts import CreateContractSerializer
|
|
||||||
from core.apps.companies.permissions.folders import IsFolderOwner
|
from core.apps.companies.permissions.folders import IsFolderOwner
|
||||||
|
|
||||||
|
from core.utils.views import BaseApiViewMixin
|
||||||
|
from core.apps.contracts.serializers.contracts import CreateContractSerializer
|
||||||
from core.apps.companies.models import CompanyFolderModel
|
from core.apps.companies.models import CompanyFolderModel
|
||||||
from core.apps.companies.serializers.folders import (
|
from core.apps.companies.serializers.folders import (
|
||||||
CreateCompanyFolderSerializer,
|
CreateCompanyFolderSerializer,
|
||||||
@@ -48,24 +49,25 @@ class CompanyFolderCrudViewSet(BaseViewSetMixin, ModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# /contract-folders/<uuid:pk>/contracts
|
# /company-folders/<uuid:pk>/contracts
|
||||||
######################################################################
|
######################################################################
|
||||||
class ContractFolderApiView(GenericAPIView):
|
class ContractFolderApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||||
queryset = CompanyFolderModel.objects.all()
|
queryset = CompanyFolderModel.objects.all()
|
||||||
permission_classes = [AllowAny]
|
permission_classes = [IsFolderOwner]
|
||||||
serializer_class = None
|
serializer_class = CreateContractSerializer
|
||||||
|
|
||||||
def get_serializer_class(self): # type: ignore
|
method_permission_classes = {
|
||||||
if self.request.method == "POST":
|
"post": [IsFolderOwner]
|
||||||
return CreateContractSerializer
|
}
|
||||||
return self.serializer_class
|
method_serializer_class = {
|
||||||
|
"post": CreateContractSerializer
|
||||||
|
}
|
||||||
|
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
summary="Create Contract For Folder",
|
summary="Create Contract For Folder",
|
||||||
description="Create Contract For Folder",
|
description="Create Contract For Folder",
|
||||||
)
|
)
|
||||||
@action(methods=["POST"], detail=True, url_path="contracts")
|
def post(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
||||||
def create_contract(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
folder = cast(CompanyFolderModel, self.get_object())
|
folder = cast(CompanyFolderModel, self.get_object())
|
||||||
ser = cast(CreateContractSerializer, self.get_serializer(data=request.data)) # type: ignore
|
ser = cast(CreateContractSerializer, self.get_serializer(data=request.data)) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user