From 9742eb819c2948864add545f31ba565828f5ffa6 Mon Sep 17 00:00:00 2001 From: Ashish Acharya Date: Fri, 2 Feb 2024 11:15:15 -0600 Subject: [PATCH] Add endpoint for reading enviromental_justice data --- environmental_justice/serializers.py | 26 ++++++++++++++++++++++++++ environmental_justice/views.py | 18 ++++++++++++++++-- sde_collections/urls.py | 3 +++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 environmental_justice/serializers.py diff --git a/environmental_justice/serializers.py b/environmental_justice/serializers.py new file mode 100644 index 00000000..31c5937c --- /dev/null +++ b/environmental_justice/serializers.py @@ -0,0 +1,26 @@ +from rest_framework import serializers + +from .models import EnvironmentalJusticeRow + + +class EnvironmentalJusticeRowSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = EnvironmentalJusticeRow + fields = [ + "dataset", + "description", + "description_simplified", + "indicators", + "intended_use", + "latency", + "limitations", + "project", + "source_link", + "strengths", + "format", + "geographic_coverage", + "data_visualization", + "spatial_resolution", + "temporal_extent", + "temporal_resolution", + ] diff --git a/environmental_justice/views.py b/environmental_justice/views.py index 6100593b..8ff1ce51 100644 --- a/environmental_justice/views.py +++ b/environmental_justice/views.py @@ -1,3 +1,17 @@ -from django.shortcuts import render # noqa +from rest_framework import permissions, viewsets -# Create your views here. +from .models import EnvironmentalJusticeRow +from .serializers import EnvironmentalJusticeRowSerializer + + +class EnvironmentalJusticeRowViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows environmental justice rows to be read. + """ + + queryset = EnvironmentalJusticeRow.objects.all() + serializer_class = EnvironmentalJusticeRowSerializer + permission_classes = [permissions.IsAuthenticated] + http_method_names = [ + "get", + ] diff --git a/sde_collections/urls.py b/sde_collections/urls.py index ab071d4a..3953517e 100644 --- a/sde_collections/urls.py +++ b/sde_collections/urls.py @@ -1,6 +1,8 @@ from django.urls import include, path from rest_framework import routers +from environmental_justice.views import EnvironmentalJusticeRowViewSet + from . import views router = routers.DefaultRouter() @@ -11,6 +13,7 @@ router.register(r"include-patterns", views.IncludePatternViewSet) router.register(r"title-patterns", views.TitlePatternViewSet) router.register(r"document-type-patterns", views.DocumentTypePatternViewSet) +router.register(r"environmental-justice", EnvironmentalJusticeRowViewSet) app_name = "sde_collections"