Skip to content

Commit

Permalink
update our schema documentation for various views
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Oct 10, 2023
1 parent 43f88c4 commit 8816fd7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
20 changes: 16 additions & 4 deletions server/apps/sites/views/site_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from django.db.models import QuerySet
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from drf_spectacular.utils import extend_schema, inline_serializer
Expand Down Expand Up @@ -62,6 +63,17 @@ class RcraSiteView(RetrieveAPIView):
permission_classes = [permissions.IsAuthenticated]


@extend_schema(
responses=RcraSiteSerializer(many=True),
request=inline_serializer(
"handler_search",
fields={
"epaId": serializers.CharField(),
"siteName": serializers.CharField(),
"siteType": serializers.CharField(),
},
),
)
class SiteSearchView(ListAPIView):
"""
Search for locally saved hazardous waste sites ("Generators", "Transporters", "Tsdf's")
Expand All @@ -70,11 +82,11 @@ class SiteSearchView(ListAPIView):
queryset = RcraSite.objects.all()
serializer_class = RcraSiteSerializer

def get_queryset(self):
def get_queryset(self: ListAPIView) -> QuerySet[RcraSite]:
queryset = RcraSite.objects.all()
epa_id_param = self.request.query_params.get("epaId")
name_param = self.request.query_params.get("siteName")
site_type_param: str = self.request.query_params.get("siteType")
epa_id_param: str | None = self.request.query_params.get("epaId")
name_param: str | None = self.request.query_params.get("siteName")
site_type_param: str | None = self.request.query_params.get("siteType")
if epa_id_param is not None:
queryset = queryset.filter(epa_id__icontains=epa_id_param)
if name_param is not None:
Expand Down
2 changes: 1 addition & 1 deletion server/apps/trak/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
include(
[
# Manifest
path("manifest", CreateRcraManifestView.as_view()),
path("manifest/<str:mtn>", ManifestView.as_view()),
path("manifest/create", CreateRcraManifestView.as_view()),
path("manifest/sign", SignManifestView.as_view()),
path("manifest/sync", SyncSiteManifestView.as_view()),
# MTN
Expand Down
21 changes: 15 additions & 6 deletions server/apps/trak/views/manifest_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from celery.exceptions import TaskError
from celery.result import AsyncResult
from django.db.models import Q
from drf_spectacular.utils import extend_schema
from rest_framework import status
from drf_spectacular.utils import extend_schema, inline_serializer
from rest_framework import serializers, status
from rest_framework.generics import GenericAPIView, ListAPIView, RetrieveAPIView
from rest_framework.request import Request
from rest_framework.response import Response
Expand Down Expand Up @@ -86,15 +86,24 @@ def post(self, request: Request) -> Response:
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data=exc)


@extend_schema(
request=inline_serializer(
"site_manifest_sync_request", fields={"siteId": serializers.CharField()}
),
responses=inline_serializer(
"site_manifest_sync_response", fields={"task": serializers.CharField()}
),
)
class SyncSiteManifestView(GenericAPIView):
"""
This endpoint launches a task to pull a site's manifests that are out of sync with RCRAInfo
Pull a site's manifests that are out of sync with RCRAInfo.
It returns the task id of the long-running background task which can be used to poll
for status.
"""

queryset = None

def post(self, request: Request) -> Response:
"""POST method rcra_site"""
try:
site_id = request.data["siteId"]
task = sync_site_manifests.delay(site_id=site_id, username=str(request.user))
Expand All @@ -105,17 +114,17 @@ def post(self, request: Request) -> Response:
)


@extend_schema(request=ManifestSerializer)
class CreateRcraManifestView(GenericAPIView):
"""
This is a proxy endpoint used to create electronic manifest(s) in RCRAInfo/e-Manifest
A proxy endpoint used to create electronic manifest(s) in RCRAInfo/e-Manifest
"""

queryset = None
serializer_class = ManifestSerializer
http_method_names = ["post"]

def post(self, request: Request) -> Response:
"""The Body of the POST request should contain the complete and valid manifest object"""
manifest_serializer = self.serializer_class(data=request.data)
if manifest_serializer.is_valid():
logger.debug(
Expand Down

0 comments on commit 8816fd7

Please sign in to comment.