list applicatin url

This commit is contained in:
mahdavi 2022-09-15 12:49:10 +04:30
parent af2fb55457
commit 0bf6777c62
4 changed files with 49 additions and 5 deletions

17
apps/superapp/serializers.py Executable file
View file

@ -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',
)

View file

@ -1,8 +1,10 @@
from django.urls import path from django.urls import path
from .views import AppListView, AppDetailView from .views import AppListView, AppDetailView, AppListAPIView
app_name = "superapp" app_name = "superapp"
urlpatterns = [ urlpatterns = [
path('api/applications/', AppListAPIView.as_view(), name='app_list_api'),
path('', AppListView.as_view(), name='app_list'), path('', AppListView.as_view(), name='app_list'),
path('<uuid>', AppDetailView.as_view(), name='app_detail'), path('<uuid>', AppDetailView.as_view(), name='app_detail'),
] ]

View file

@ -2,7 +2,12 @@ from django.contrib.auth.decorators import login_required
from django.shortcuts import render from django.shortcuts import render
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from rest_framework import generics
from .models import App from .models import App
from .serializers import AppSerializer
from ..gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
class AppListView(ListView): class AppListView(ListView):
@ -18,3 +23,14 @@ class AppDetailView(DetailView):
# def get_queryset(self): # def get_queryset(self):
# return App.objects.filter(type=App.AppTypeChoices.EXTERNAL) # 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()

View file

@ -26,7 +26,7 @@ class ApiClient():
"username": phone_number, "username": phone_number,
"password": password, "password": password,
# "scope": 'introspection', # "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_fields": 'phone_number:otp'
} }
auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET) auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET)
@ -48,7 +48,7 @@ class ApiClient():
"grant_type": "password", "grant_type": "password",
"username": phone_number, "username": phone_number,
"password": token, "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_fields": 'phone_number:ott'
} }
auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET) auth = (OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET)
@ -142,6 +142,14 @@ class ApiClient():
result = self._request(path=path) result = self._request(path=path)
return result 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): def get_transactions(self, page=None):
path = 'wallet/api/transactions/' path = 'wallet/api/transactions/'
if page: if page:
@ -218,8 +226,9 @@ class ApiClient():
client = ApiClient('+989106853582') client = ApiClient('+989106853582')
client.request_otp() client.request_otp()
client.otp_login('12345') client.otp_login('12345')
print(client.get_application_token()) print(client.get_application_list())
print(client.ott_login('abcdef12345')) # print(client.get_application_token())
# print(client.ott_login('abcdef12345'))
# print(client.create_invoice(2000, 10)) # print(client.create_invoice(2000, 10))
# print(client.pay_invoice('7967a76a-5de1-48b2-92ac-1b0f39f7223b')) # print(client.pay_invoice('7967a76a-5de1-48b2-92ac-1b0f39f7223b'))