Skip to content

Commit

Permalink
Add API to fetch attributes of a layer
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer committed Jan 6, 2025
1 parent 60fecc9 commit d8a85ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
15 changes: 14 additions & 1 deletion django_project/cloud_native_gis/api/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from cloud_native_gis.models.layer import Layer
from cloud_native_gis.models.layer_upload import LayerUpload
from cloud_native_gis.models.style import Style
from cloud_native_gis.serializer.layer import LayerSerializer
from cloud_native_gis.serializer.layer import (
LayerSerializer, LayerAttributeSerializer
)
from cloud_native_gis.serializer.layer_upload import LayerUploadSerializer
from cloud_native_gis.serializer.style import LayerStyleSerializer
from cloud_native_gis.utils.layer import layer_style_url, maputnik_url
Expand Down Expand Up @@ -169,3 +171,14 @@ def post(self, request, layer_id):
).save(file.name, file)
instance.save()
return Response('Uploaded')


class LayerAttributesViewSet(LayerObjectViewSet):
"""API layer attributes."""

serializer_class = LayerAttributeSerializer

def get_queryset(self):
"""Return queryset of API."""
layer = self._get_layer()
return layer.layerattributes_set.all()
10 changes: 9 additions & 1 deletion django_project/cloud_native_gis/serializer/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from rest_framework import serializers

from cloud_native_gis.models.layer import Layer
from cloud_native_gis.models.layer import Layer, LayerAttributes
from cloud_native_gis.models.style import Style
from cloud_native_gis.serializer.general import LicenseSerializer
from cloud_native_gis.utils.layer import layer_style_url
Expand Down Expand Up @@ -60,3 +60,11 @@ def get_license(self, obj: Layer):
class Meta: # noqa: D106
model = Layer
exclude = ['unique_id']


class LayerAttributeSerializer(serializers.ModelSerializer):
"""Serializer for layer attribute."""

class Meta: # noqa: D106
model = LayerAttributes
exclude = ['layer']
15 changes: 9 additions & 6 deletions django_project/cloud_native_gis/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from django.urls import include, path
from django.views.generic import TemplateView
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions
from rest_framework.routers import DefaultRouter
from rest_framework_nested.routers import NestedSimpleRouter

from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

from cloud_native_gis.api.layer import (
LayerViewSet, LayerStyleViewSet, LayerUploadViewSet
LayerViewSet, LayerStyleViewSet, LayerUploadViewSet,
LayerAttributesViewSet
)
from cloud_native_gis.api.vector_tile import VectorTileLayer

Expand All @@ -28,7 +28,6 @@
permission_classes=(permissions.AllowAny,),
)


router = DefaultRouter()
router.register(
r'layer', LayerViewSet, basename='cloud-native-gis-layer'
Expand All @@ -44,6 +43,10 @@
'layer-upload', LayerUploadViewSet,
basename='cloud-native-gis-layer-upload'
)
layer_router.register(
'attributes', LayerAttributesViewSet,
basename='cloud-native-layer-attributes'
)

urlpatterns = [
path(
Expand Down

0 comments on commit d8a85ce

Please sign in to comment.