fix: Swagger schema fix, comments add
This commit is contained in:
@@ -4,11 +4,11 @@ from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.permissions import AllowAny, IsAdminUser, IsAuthenticated # type: ignore
|
||||
from rest_framework.viewsets import ModelViewSet # type: ignore
|
||||
from rest_framework.views import APIView # type: ignore
|
||||
from rest_framework.generics import GenericAPIView # type: ignore
|
||||
from core.utils.views import BaseApiViewMixin
|
||||
|
||||
from rest_framework.request import HttpRequest # type: ignore
|
||||
from rest_framework.response import Response # type: ignore
|
||||
from rest_framework.decorators import action # type: ignore
|
||||
from rest_framework.generics import get_object_or_404 # type: ignore
|
||||
from rest_framework import status # type: ignore
|
||||
|
||||
from django_core.mixins import BaseViewSetMixin # type: ignore
|
||||
@@ -29,8 +29,11 @@ from core.apps.contracts.serializers import (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema(tags=["Contract"])
|
||||
class ContractView(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @view-set | ALL - /contracts
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contracts"])
|
||||
class ContractViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
queryset = ContractModel.objects.all()
|
||||
serializer_class = ListContractSerializer
|
||||
permission_classes = [AllowAny]
|
||||
@@ -60,83 +63,103 @@ class ContractView(BaseViewSetMixin, ModelViewSet):
|
||||
return super().create(request, *args, **kwargs) # type: ignore
|
||||
|
||||
|
||||
class ContractRelationsViewSet(BaseViewSetMixin, ModelViewSet):
|
||||
###################################################################################
|
||||
# @api-view | GET - /contracts/{id}/owners
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Owners"])
|
||||
class ContractOwnerApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
action_permission_classes = {
|
||||
"list_file": [AllowAny],
|
||||
"list_owner": [AllowAny],
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
action_serializer_class = { # type: ignore
|
||||
"list_file": ListContractAttachedFileSerializer,
|
||||
"list_owner": RetrieveContractOwnerSerializer,
|
||||
method_serializer_class = {
|
||||
"get": RetrieveContractOwnerSerializer,
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Owners",
|
||||
description="Get list of owners"
|
||||
)
|
||||
def get(self, *args: object, **kwargs: object) -> Response:
|
||||
contract = self.get_object()
|
||||
owners = ContractOwnerModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=owners, many=True)
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
|
||||
###################################################################################
|
||||
# @api-view | GET - /contracts/{id}/files
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Attached Files"])
|
||||
class ContractAttachedFileApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": ListContractAttachedFileSerializer,
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Files",
|
||||
description="Get List Of Files"
|
||||
)
|
||||
@action(url_path="files", detail=True, methods=["GET"])
|
||||
def list_file(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = get_object_or_404(ContractModel, pk=pk)
|
||||
def get(self, *args: object, **kwargs: object) -> Response:
|
||||
contract = self.get_object()
|
||||
files = ContractAttachedFileModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=files, many=True) # type: ignore
|
||||
ser = self.get_serializer(instance=files, many=True)
|
||||
return Response(data=ser.data, status=status.HTTP_200_OK)
|
||||
|
||||
@extend_schema(
|
||||
summary="Get List Of Owners",
|
||||
description="Get list of owners"
|
||||
)
|
||||
@action(url_path="owners", detail=True, methods=["GET"])
|
||||
def list_owner(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = get_object_or_404(ContractModel, pk=pk)
|
||||
owners = ContractOwnerModel.objects.filter(contract=contract)
|
||||
ser = self.get_serializer(instance=owners, many=True) # type: ignore
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ContractDetailView(APIView):
|
||||
###################################################################################
|
||||
# @api-view | GET - /contract-owners/{id}/contract
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contract Owners"])
|
||||
class ContractDetailApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": RetrieveContractSerializer
|
||||
}
|
||||
|
||||
@extend_schema(
|
||||
summary="Uploads a file for contract attached files",
|
||||
description="Creates a file for contract attached files.",
|
||||
)
|
||||
def get(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
owner_id: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
contract = ContractModel.objects.filter(owners__id=owner_id)[0]
|
||||
ser = RetrieveContractSerializer(instance=contract)
|
||||
def get(self, request: HttpRequest, pk: uuid.UUID, *args: object, **kwargs: object) -> Response:
|
||||
contract = ContractModel.objects.filter(owners__id=pk)[0]
|
||||
ser = self.get_serializer(instance=contract) # type: ignore
|
||||
return Response(ser.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ListFolderContractsView(APIView):
|
||||
permission_classes = [IsAdminUser]
|
||||
###################################################################################
|
||||
# @api-view | GET - /folders/{id}/contracts
|
||||
###################################################################################
|
||||
@extend_schema(tags=["Contracts"])
|
||||
class ListFolderContractsApiView(BaseApiViewMixin, GenericAPIView): # type: ignore
|
||||
permission_classes = [AllowAny]
|
||||
queryset = ContractOwnerModel.objects.all()
|
||||
|
||||
method_permission_classes = {
|
||||
"get": [AllowAny]
|
||||
}
|
||||
method_serializer_class = {
|
||||
"get": ListContractSerializer
|
||||
}
|
||||
|
||||
def get(
|
||||
self,
|
||||
request: HttpRequest,
|
||||
pk: uuid.UUID,
|
||||
*args: object,
|
||||
**kwargs: object
|
||||
) -> Response:
|
||||
@extend_schema(
|
||||
summary="Get Contracts related to folders",
|
||||
description="Get Contracts related to folders",
|
||||
)
|
||||
def get(self, request: HttpRequest, pk: uuid.UUID, *args: object, **kwargs: object) -> Response:
|
||||
contracts = ContractModel.objects.filter(folders__id=pk)
|
||||
ser = ListContractSerializer(instance=contracts, many=True)
|
||||
ser = self.get_serializer(instance=contracts, many=True) # type: ignore
|
||||
return Response(ser.data, status.HTTP_200_OK)
|
||||
|
||||
Reference in New Issue
Block a user