fix: company/<id>/... views are done
This commit is contained in:
@@ -7,9 +7,7 @@ router = DefaultRouter()
|
|||||||
|
|
||||||
router.register(r"company-accounts", views.CompanyAccountCrudViewSet, "company-account-view-set") # type: ignore
|
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-folders", views.CompanyFolderCrudViewSet, "company-folders-view-set") # type: ignore
|
||||||
# router.register(r"company-folders", views.ContractFolderApiView, "folders-contracts-view-set") # type: ignore
|
|
||||||
router.register(r"companies", views.CompanyCrudViewSet, "companies-view-set") # type: ignore
|
router.register(r"companies", views.CompanyCrudViewSet, "companies-view-set") # type: ignore
|
||||||
# router.register(r"companies", views.CompanyAccountView, "companies-accounts-view") # type: ignore
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns: list[object] = [
|
urlpatterns: list[object] = [
|
||||||
@@ -22,6 +20,11 @@ urlpatterns: list[object] = [
|
|||||||
path(
|
path(
|
||||||
r"companies/<uuid:pk>/contracts",
|
r"companies/<uuid:pk>/contracts",
|
||||||
views.CompanyContractApiView.as_view(),
|
views.CompanyContractApiView.as_view(),
|
||||||
name="company-contracts"
|
name="company-contracts-api-view"
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
r"companies/<uuid:pk>/accounts",
|
||||||
|
views.CompanyAccountApiView.as_view(),
|
||||||
|
name="company-accounts-api-view"
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from typing import Any
|
|
||||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
@@ -70,8 +69,9 @@ class CompanyCrudViewSet(BaseViewSetMixin, ModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# company/<uuid:pk>/contract Views
|
# company/<uuid:pk>/contract
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@extend_schema(tags=["Company Contracts"])
|
||||||
class CompanyContractApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
class CompanyContractApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||||
queryset = CompanyModel.objects.all()
|
queryset = CompanyModel.objects.all()
|
||||||
permission_classes = [IsCompanyAccount]
|
permission_classes = [IsCompanyAccount]
|
||||||
@@ -110,33 +110,26 @@ class CompanyContractApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
|||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# company/<uuid:pk>/accounts Views
|
# company/<uuid:pk>/accounts
|
||||||
######################################################################
|
######################################################################
|
||||||
class CompanyAccountView(GenericAPIView):
|
@extend_schema(tags=["Company Accounts"])
|
||||||
|
class CompanyAccountApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||||
queryset = CompanyModel.objects.all()
|
queryset = CompanyModel.objects.all()
|
||||||
serializer_class = None
|
serializer_class = RetrieveCompanyAccountSerializer
|
||||||
permission_classes = [IsCompanyAccount]
|
permission_classes = [IsCompanyAccount]
|
||||||
|
|
||||||
action_serializer_class = {
|
method_serializer_class = {
|
||||||
"list_account": RetrieveCompanyAccountSerializer
|
"get": RetrieveCompanyAccountSerializer
|
||||||
|
}
|
||||||
|
method_permission_classes = {
|
||||||
|
"get": [IsCompanyAccount]
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_serializer_class(self):
|
|
||||||
if self.request.method == "GET":
|
|
||||||
return RetrieveCompanyAccountSerializer
|
|
||||||
return RetrieveCompanyFolderSerializer
|
|
||||||
|
|
||||||
@extend_schema(
|
@extend_schema(
|
||||||
summary="List company accounts",
|
summary="List company accounts",
|
||||||
description="List Company Accounts"
|
description="List Company Accounts"
|
||||||
)
|
)
|
||||||
@action(url_path="accounts", detail=True, methods=["GET"])
|
def get(self, *args: object, **kwargs: object) -> Response:
|
||||||
def list_account(
|
|
||||||
self,
|
|
||||||
request: HttpRequest,
|
|
||||||
*args: object,
|
|
||||||
**kwargs: object,
|
|
||||||
) -> Response:
|
|
||||||
company = self.get_object()
|
company = self.get_object()
|
||||||
accounts = CompanyAccountModel.objects.filter(company=company)
|
accounts = CompanyAccountModel.objects.filter(company=company)
|
||||||
ser = self.get_serializer(instance=accounts, many=True) # type: ignore
|
ser = self.get_serializer(instance=accounts, many=True) # type: ignore
|
||||||
@@ -144,25 +137,36 @@ class CompanyAccountView(GenericAPIView):
|
|||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# company/<uuid:pk>/folders Views
|
# company/<uuid:pk>/folders
|
||||||
######################################################################
|
######################################################################
|
||||||
class CompanyFolderApiView(GenericAPIView):
|
@extend_schema(tags=["Company Folders"])
|
||||||
|
class CompanyFolderApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||||
queryset = CompanyModel.objects.all()
|
queryset = CompanyModel.objects.all()
|
||||||
permission_classes = [IsCompanyAccount]
|
permission_classes = [IsCompanyAccount]
|
||||||
|
|
||||||
def get_serializer_class(self): # type: ignore
|
method_serializer_class = {
|
||||||
if self.request.method == "POST":
|
"get": RetrieveCompanyFolderSerializer,
|
||||||
return CreateFolderForCompanySerializer
|
"post": CreateFolderForCompanySerializer,
|
||||||
return RetrieveCompanyFolderSerializer
|
}
|
||||||
|
method_permission_classes = {
|
||||||
|
"get": [IsCompanyAccount],
|
||||||
|
"get": [IsCompanyAccount],
|
||||||
|
}
|
||||||
|
|
||||||
@extend_schema(summary="List Company Folders")
|
@extend_schema(
|
||||||
def get(self, request: HttpRequest, *args: object, **kwargs: object) -> Response:
|
summary="List Company Folders",
|
||||||
|
description="List Company Folders",
|
||||||
|
)
|
||||||
|
def get(self, *args: object, **kwargs: object) -> Response:
|
||||||
company = self.get_object()
|
company = self.get_object()
|
||||||
folders = CompanyFolderModel.objects.filter(company=company)
|
folders = CompanyFolderModel.objects.filter(company=company)
|
||||||
serializer = self.get_serializer(instance=folders, many=True)
|
serializer = self.get_serializer(instance=folders, many=True)
|
||||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
@extend_schema(summary="Create Folder for Company")
|
@extend_schema(
|
||||||
|
summary="Create Folder for Company",
|
||||||
|
description="Create Folder for Company",
|
||||||
|
)
|
||||||
def post(self, request: HttpRequest, *args: object, **kwargs: object):
|
def post(self, request: HttpRequest, *args: object, **kwargs: object):
|
||||||
company = self.get_object()
|
company = self.get_object()
|
||||||
serializer = self.get_serializer(data=request.data, context={"company_id": company.pk})
|
serializer = self.get_serializer(data=request.data, context={"company_id": company.pk})
|
||||||
|
|||||||
Reference in New Issue
Block a user