feat: add new api
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework.exceptions import NotFound, PermissionDenied
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet
|
||||
from rest_framework.parsers import FormParser, MultiPartParser
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel
|
||||
from core.apps.evaluation.models import DocumentModel, ValuationDocumentModel, AutoEvaluationModel
|
||||
from core.apps.evaluation.serializers.document import (
|
||||
CreateDocumentSerializer,
|
||||
CreateValuationdocumentSerializer,
|
||||
@@ -42,3 +46,20 @@ class DocumentView(BaseViewSetMixin, ModelViewSet):
|
||||
"retrieve": RetrieveDocumentSerializer,
|
||||
"create": CreateDocumentSerializer,
|
||||
}
|
||||
|
||||
@extend_schema(summary="Auto evaluation documents.", description="get auto evaluation documents.")
|
||||
@action(methods=["GET"], detail=False, url_path=r"auto_evaluation/(?P<auto_evaluation_id>\d+)")
|
||||
def auto_evaluation(self, request, auto_evaluation_id=None):
|
||||
try:
|
||||
auto_evaluation = get_object_or_404(AutoEvaluationModel, id=auto_evaluation_id)
|
||||
documents = DocumentModel.objects.filter(auto_evaluation=auto_evaluation)
|
||||
page = self.paginate_queryset(documents)
|
||||
if page is not None:
|
||||
serializer = ListDocumentSerializer(page, many=True)
|
||||
return self.get_paginated_response(serializer.data)
|
||||
serializer = ListDocumentSerializer(documents, many=True)
|
||||
return Response(serializer.data)
|
||||
except AutoEvaluationModel.DoesNotExist:
|
||||
raise NotFound("Auto evaluation not found")
|
||||
except Exception as e:
|
||||
raise PermissionDenied(e)
|
||||
|
||||
Reference in New Issue
Block a user