Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to fetch attributes of a layer #20

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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