[extensions-web/wip/api/v1] api: added new extensions-versions endpoint



commit 518389e4d18a5b94efaa81aeb92c6122d94ea64c
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Sun Mar 14 20:05:17 2021 +0400

    api: added new extensions-versions endpoint

 sweettooth/api/v1/urls.py            |  7 ++++++-
 sweettooth/extensions/serializers.py | 28 +++++++++++++++++++++-------
 sweettooth/extensions/views.py       | 12 ++++++++++++
 3 files changed, 39 insertions(+), 8 deletions(-)
---
diff --git a/sweettooth/api/v1/urls.py b/sweettooth/api/v1/urls.py
index fc980983..1b908d37 100644
--- a/sweettooth/api/v1/urls.py
+++ b/sweettooth/api/v1/urls.py
@@ -13,7 +13,7 @@ from django.urls import path
 from rest_framework.routers import SimpleRouter
 
 from sweettooth.api.v1.views import HelloView
-from sweettooth.extensions.views import ExtensionsViewSet
+from sweettooth.extensions.views import ExtensionsViewSet, ExtensionsVersionsViewSet
 from sweettooth.users.views import UserProfileDetailView
 
 # Create a router and register our viewsets with it.
@@ -23,6 +23,11 @@ router.register(
     ExtensionsViewSet,
     basename='extension',
 )
+router.register(
+    r'v1/extensions-versions',
+    ExtensionsVersionsViewSet,
+    basename='extensions-versions',
+)
 
 urlpatterns = router.urls
 urlpatterns += [
diff --git a/sweettooth/extensions/serializers.py b/sweettooth/extensions/serializers.py
index c69230de..ff02c017 100644
--- a/sweettooth/extensions/serializers.py
+++ b/sweettooth/extensions/serializers.py
@@ -13,6 +13,7 @@ from rest_framework import serializers
 from sweettooth.extensions.models import Extension, ExtensionVersion, ShellVersion
 from sweettooth.users.serializers import BaseUserProfileSerializer
 
+
 class ShellVersionSerializer(serializers.ModelSerializer):
     class Meta:
         model = ShellVersion
@@ -22,13 +23,6 @@ class ShellVersionSerializer(serializers.ModelSerializer):
             'point',
         ]
 
-class ExtensionVersionSerializer(serializers.ModelSerializer):
-    class Meta:
-        model = ExtensionVersion
-        fields = [
-            'version',
-            'status',
-        ]
 
 class ExtensionSerializer(serializers.ModelSerializer):
     creator = BaseUserProfileSerializer(many=False, read_only=True)
@@ -50,3 +44,23 @@ class ExtensionSerializer(serializers.ModelSerializer):
             'rating',
             'rated',
         ]
+
+
+class ExtensionVersionSerializer(serializers.ModelSerializer):
+    # TODO: change primary key to UUID
+    extension = serializers.SlugRelatedField(
+        many=False,
+        read_only=True,
+        slug_field='uuid'
+     )
+    shell_versions = ShellVersionSerializer(many=True, read_only=True)
+
+    class Meta:
+        model = ExtensionVersion
+        fields = [
+            'extension',
+            'version',
+            'status',
+            'shell_versions',
+            'created',
+        ]
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index eee9c1e8..a3e52b72 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -184,6 +184,18 @@ class ExtensionsViewSet(mixins.ListModelMixin,
         })
 
 
+class ExtensionsVersionsViewSet(mixins.ListModelMixin,
+                                viewsets.GenericViewSet):
+    queryset = models.ExtensionVersion.objects.order_by('extension', 'version')
+    serializer_class = serializers.ExtensionVersionSerializer
+    pagination_class = ExtensionsPagination
+    filter_backends = [DjangoFilterBackend]
+    filterset_fields = ['extension__uuid']
+    page_size = 25
+    page_size_query_param = 'page_size'
+    max_page_size = 100
+
+
 def get_versions_for_version_strings(version_strings):
     def get_version(major, minor, point):
         try:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]