From de6ef1514d03152afc40db0f205376d1f8d4f2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Wed, 15 May 2024 12:50:38 +0200 Subject: [PATCH] sources apis --- config/routers.py | 1 + metadata_catalogue/maps/api/serializers.py | 13 +++++++++++++ metadata_catalogue/maps/api/views.py | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config/routers.py b/config/routers.py index a0e1626..68c8870 100644 --- a/config/routers.py +++ b/config/routers.py @@ -6,6 +6,7 @@ router = routers.DefaultRouter() router.register(r"maps", views.MapViewSet, basename="maps") +router.register(r"sources", views.SourceViewSet, basename="sources") router.register(r"raster-sources", views.RasterSourceViewSet, basename="raster-sources") router.register(r"vector-sources", views.VectorSourceViewSet, basename="vector-sources") router.register(r"layer-groups", views.LayerGroupViewSet, basename="layer-groups") diff --git a/metadata_catalogue/maps/api/serializers.py b/metadata_catalogue/maps/api/serializers.py index 73d2118..a2c8da7 100644 --- a/metadata_catalogue/maps/api/serializers.py +++ b/metadata_catalogue/maps/api/serializers.py @@ -25,6 +25,19 @@ class Meta: ] +class SourceSerializer(serializers.ModelSerializer): + class Meta: + model = Source + fields = [ + "name", + "slug", + "extra", + "style", + "attribution", + "metadata", + ] + + class RasterSourceBaseSerializer(serializers.ModelSerializer): class Meta: model = RasterSource diff --git a/metadata_catalogue/maps/api/views.py b/metadata_catalogue/maps/api/views.py index fb94c4b..81f72b2 100644 --- a/metadata_catalogue/maps/api/views.py +++ b/metadata_catalogue/maps/api/views.py @@ -4,13 +4,14 @@ from rest_framework.parsers import MultiPartParser from rest_framework.response import Response -from ..models import Layer, LayerGroup, Map, RasterSource, VectorSource +from ..models import Layer, LayerGroup, Map, RasterSource, Source, VectorSource from .serializers import ( FileUploadSerializer, LayerGroupSerializer, LayerSerializer, MapSerializer, RasterSourceSerializer, + SourceSerializer, VectorSourceSerializer, ) @@ -29,6 +30,12 @@ class MapViewSet(viewsets.ModelViewSet): } +class SourceViewSet(viewsets.ModelViewSet): + queryset = Source.objects.all() + lookup_field = "slug" + serializer_class = SourceSerializer + + class UploadableMixin: @action(detail=True, methods=["post"], parser_classes=(MultiPartParser,)) def upload(self, request, *args, **kwargs):