diff --git a/apps/superapp/serializers.py b/apps/superapp/serializers.py new file mode 100755 index 0000000..a699c92 --- /dev/null +++ b/apps/superapp/serializers.py @@ -0,0 +1,17 @@ +from rest_framework import serializers +from rest_framework.exceptions import APIException + +from apps.users.serializers import PublicUserSerializer +from .models import App + + +class AppSerializer(serializers.ModelSerializer): + class Meta: + model = App + fields = ('title', + 'description', + 'order', + "logo", + "type", + 'url', + ) diff --git a/apps/superapp/urls.py b/apps/superapp/urls.py index 17bf366..a715cbd 100644 --- a/apps/superapp/urls.py +++ b/apps/superapp/urls.py @@ -1,8 +1,10 @@ from django.urls import path -from .views import AppListView, AppDetailView +from .views import AppListView, AppDetailView, AppListAPIView + app_name = "superapp" urlpatterns = [ + path('api/applications/', AppListAPIView.as_view(), name='app_list_api'), path('', AppListView.as_view(), name='app_list'), path('', AppDetailView.as_view(), name='app_detail'), ] \ No newline at end of file diff --git a/apps/superapp/views.py b/apps/superapp/views.py index 6d2c851..9b44226 100644 --- a/apps/superapp/views.py +++ b/apps/superapp/views.py @@ -2,7 +2,12 @@ from django.contrib.auth.decorators import login_required from django.shortcuts import render from django.utils.decorators import method_decorator from django.views.generic import ListView, DetailView +from rest_framework import generics + from .models import App +from .serializers import AppSerializer +from ..gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements + @method_decorator(login_required, name='dispatch') class AppListView(ListView): @@ -18,3 +23,14 @@ class AppDetailView(DetailView): # def get_queryset(self): # return App.objects.filter(type=App.AppTypeChoices.EXTERNAL) + + +class AppListAPIView(generics.ListAPIView): + permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements] + serializer_class = AppSerializer + required_alternate_scopes = { + "GET": [['superapp.applications:list']], + } + + def get_queryset(self): + return App.objects.all() diff --git a/client.py b/client.py index 43cd265..6160ab3 100644 --- a/client.py +++ b/client.py @@ -26,7 +26,7 @@ class ApiClient(): "username": phone_number, "password": password, # "scope": 'introspection', - "scope": 'introspection accounts.account:request_ott accounts.profile:list accounts.profile:retrieve accounts.account:retrieve accounts.account:update accounts.profile:inquiry accounts.account:change_password wallet.transaction:list wallet.invoice:create wallet.transaction:retrieve wallet.invoice:pay wallet.invoice:receipt wallet.deposit:submit wallet.deposit:verify wallet.withdraw:submit wallet.withdraw:verify ', + "scope": 'introspection superapp.applications:list accounts.account:request_ott accounts.profile:list accounts.profile:retrieve accounts.account:retrieve accounts.account:update accounts.profile:inquiry accounts.account:change_password wallet.transaction:list wallet.invoice:create wallet.transaction:retrieve wallet.invoice:pay wallet.invoice:receipt wallet.deposit:submit wallet.deposit:verify wallet.withdraw:submit wallet.withdraw:verify ', "auth_fields": 'phone_number:otp' } auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET) @@ -48,7 +48,7 @@ class ApiClient(): "grant_type": "password", "username": phone_number, "password": token, - "scope": 'introspection accounts.account:request_ott accounts.profile:list accounts.profile:retrieve accounts.account:retrieve accounts.account:update accounts.profile:inquiry accounts.account:change_password wallet.transaction:list wallet.invoice:create wallet.transaction:retrieve wallet.invoice:pay wallet.invoice:receipt wallet.deposit:submit wallet.deposit:verify wallet.withdraw:submit wallet.withdraw:verify ', + "scope": 'introspection superapp.applications:list accounts.account:request_ott accounts.profile:list accounts.profile:retrieve accounts.account:retrieve accounts.account:update accounts.profile:inquiry accounts.account:change_password wallet.transaction:list wallet.invoice:create wallet.transaction:retrieve wallet.invoice:pay wallet.invoice:receipt wallet.deposit:submit wallet.deposit:verify wallet.withdraw:submit wallet.withdraw:verify ', "auth_fields": 'phone_number:ott' } auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET) @@ -142,6 +142,14 @@ class ApiClient(): result = self._request(path=path) return result + def get_application_list(self, page=None): + path = 'api/applications/' + if page: + page = int(page) + path = f'{path}?page={page}' + + return self._request(path=path) + def get_transactions(self, page=None): path = 'wallet/api/transactions/' if page: @@ -218,8 +226,9 @@ class ApiClient(): client = ApiClient('+989106853582') client.request_otp() client.otp_login('12345') -print(client.get_application_token()) -print(client.ott_login('abcdef12345')) +print(client.get_application_list()) +# print(client.get_application_token()) +# print(client.ott_login('abcdef12345')) # print(client.create_invoice(2000, 10)) # print(client.pay_invoice('7967a76a-5de1-48b2-92ac-1b0f39f7223b'))