From 5860a586a29d2911dc8d3284ec21dbf1ddc4927e Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Fri, 20 Aug 2021 17:38:36 +0530 Subject: [PATCH] feat: introduce steward endpoint (#9377) --- app/app/settings.py | 1 + app/quadraticlands/router.py | 39 ++++++++++++++++++++++++++++++++ app/quadraticlands/serializer.py | 15 ++++++++++++ app/quadraticlands/urls.py | 3 +++ requirements/base.txt | 1 + 5 files changed, 59 insertions(+) create mode 100644 app/quadraticlands/router.py create mode 100644 app/quadraticlands/serializer.py diff --git a/app/app/settings.py b/app/app/settings.py index 1dce4559135..3af3c23aa13 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -111,6 +111,7 @@ 'retail', 'ptokens', 'rest_framework', + 'django_filters', 'marketing', 'economy', 'dashboard', diff --git a/app/quadraticlands/router.py b/app/quadraticlands/router.py new file mode 100644 index 00000000000..c8bf7264a8d --- /dev/null +++ b/app/quadraticlands/router.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +"""Define dashboard specific DRF API routes. + +Copyright (C) 2021 Gitcoin Core + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . + +""" +from quadraticlands.serializer import GTCStewardSerializer +from rest_framework import routers, viewsets +from rest_framework.pagination import PageNumberPagination + +from .models import GTCSteward + + +class GTCStewardPagination(PageNumberPagination): + page_size = 30 + page_size_query_param = 'page_size' + + +class GTCStewardViewSet(viewsets.ModelViewSet): + queryset = GTCSteward.objects.all() + serializer_class = GTCStewardSerializer + pagination_class = GTCStewardPagination + + +router = routers.DefaultRouter() +router.register(r'stewards', GTCStewardViewSet) diff --git a/app/quadraticlands/serializer.py b/app/quadraticlands/serializer.py new file mode 100644 index 00000000000..36fb161f844 --- /dev/null +++ b/app/quadraticlands/serializer.py @@ -0,0 +1,15 @@ +from dashboard.models import ProfileSerializer +from rest_flex_fields import FlexFieldsModelSerializer + +from .models import GTCSteward + + +class GTCStewardSerializer(FlexFieldsModelSerializer): + """Handle serializing of GTCSteward""" + class Meta: + """Define the GrantCLR serializer metadata.""" + model = GTCSteward + fields = ('profile', 'real_name', 'bio', 'gtc_address', 'profile_link', 'custom_steward_img') + expandable_fields = { + 'profile': ProfileSerializer + } diff --git a/app/quadraticlands/urls.py b/app/quadraticlands/urls.py index 133bd99eb54..bb69f964305 100644 --- a/app/quadraticlands/urls.py +++ b/app/quadraticlands/urls.py @@ -18,9 +18,11 @@ """ from django.conf import settings +from django.conf.urls import include, url from django.urls import path, re_path from quadraticlands.helpers import vote +from quadraticlands.router import router from quadraticlands.views import ( base, base_auth, dashboard_index, handler400, handler403, handler404, handler500, index, mission_diplomacy, mission_diplomacy_room, mission_index, mission_lore, mission_postcard, mission_postcard_svg, mission_schwag, @@ -52,6 +54,7 @@ path('mission/diplomacy//', mission_diplomacy_room, name='mission_diplomacy_room'), re_path(r'^mission/diplomacy/?', mission_diplomacy, name='mission_diplomacy'), + url(r'^api/v1/', include(router.urls)), ] diff --git a/requirements/base.txt b/requirements/base.txt index c572555ecda..9dc679ef069 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -116,3 +116,4 @@ libsass==0.20.1 graphqlclient==0.2.4 docutils==0.17.1 unidecode==1.2.0 +drf-flex-fields==0.9.1 \ No newline at end of file