From e7a6b632ab4053130b3c1a251c0ab87e9a2744d0 Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Thu, 5 Jun 2025 09:42:26 +0330 Subject: [PATCH 1/5] create user if not available in getting user balance --- apps/wallet/views/application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/wallet/views/application.py b/apps/wallet/views/application.py index 86a983b..74821b6 100755 --- a/apps/wallet/views/application.py +++ b/apps/wallet/views/application.py @@ -42,7 +42,8 @@ class UserBalanceAPIView(generics.RetrieveAPIView): def get_object(self): user_uuid = self.kwargs.get('uuid') - user = get_object_or_404(User.objects.all(), uuid=user_uuid) + user = User.objects.get_or_create(uuid=user_uuid) + # user = get_object_or_404(User.objects.all(), uuid=user_uuid) return user From 94b3d521d4d2566b16b8dc54a9f7ca87d59a1246 Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Thu, 5 Jun 2025 13:42:33 +0330 Subject: [PATCH 2/5] create user if not available in getting user balance --- apps/wallet/views/application.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/wallet/views/application.py b/apps/wallet/views/application.py index 74821b6..4f75456 100755 --- a/apps/wallet/views/application.py +++ b/apps/wallet/views/application.py @@ -9,7 +9,7 @@ from apps.users.models import User from apps.wallet.constans import TypeChoices, StateChoices from apps.wallet.models import Transaction from apps.wallet.serializers import ApplicationDepositSerializer, ApplicationWithdrawSerializer, \ - ApplicationTransactionSerializer, ApplicationBalanceSerializer + ApplicationTransactionSerializer, ApplicationBalanceSerializer, MyWalletSerializer def get_application(request): @@ -37,12 +37,12 @@ class UserBalanceAPIView(generics.RetrieveAPIView): API for getting specified user or application balance. ''' permission_classes = [IsAuthenticatedOrTokenHasScope] - serializer_class = ApplicationBalanceSerializer + serializer_class = MyWalletSerializer required_scopes = ['wallet.application:get_user_balance'] def get_object(self): user_uuid = self.kwargs.get('uuid') - user = User.objects.get_or_create(uuid=user_uuid) + user, created = User.objects.get_or_create(uuid=user_uuid) # user = get_object_or_404(User.objects.all(), uuid=user_uuid) return user From 6742398d898be0bd2938807ea5283d6cc7db1629 Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Wed, 18 Jun 2025 11:42:17 +0330 Subject: [PATCH 3/5] pring log --- utils/accounts_client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/accounts_client.py b/utils/accounts_client.py index 43f3177..b584285 100644 --- a/utils/accounts_client.py +++ b/utils/accounts_client.py @@ -35,6 +35,9 @@ def login_as_client_credentials(): auth=auth) auth_data = response.json() + + print(auth_data) + if 'access_token' in auth_data: auth_data['created_at'] = time.time() cache.set('wallet_access_token', auth_data, timeout=auth_data.get('expires_in')-5) From 2464cc8ae34bddb3453b6b11abf8ba8f5f4e3638 Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Wed, 18 Jun 2025 11:50:43 +0330 Subject: [PATCH 4/5] pring log --- apps/wallet/models.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/wallet/models.py b/apps/wallet/models.py index 01216c6..a0de212 100755 --- a/apps/wallet/models.py +++ b/apps/wallet/models.py @@ -215,10 +215,11 @@ class Transaction(models.Model): def update_details(self, force_update=False): if not isinstance(self.details, dict): self.details = {} - self.save() + self.save() # detail = {'payer_name', 'payee_name', 'application_name', 'payer_avatar_url', 'payee_avatar_url', 'application_avatar_url'} is_updated = False if not self.details.get('payer_name'): + print('update payer') if self.payer_type == TypeChoices.USER.value: payer_details: PublicUser = get_user_details(self.payer_id) self.details['payer_name'] = payer_details.first_name + payer_details.last_name @@ -227,10 +228,12 @@ class Transaction(models.Model): payer_details = get_application_details(self.payer_id) self.details['payer_name'] = payer_details.name #TODO: get avatar from details - is_updated = True + print("payer_details:", payer_details) + print("is_updated:", is_updated) if not self.details.get('payee_name'): + print('update payee') if self.payee_type == TypeChoices.USER.value: payee_details: PublicUser = get_user_details(self.payee_id) self.details['payee_name'] = payee_details.first_name + payee_details.last_name @@ -241,18 +244,24 @@ class Transaction(models.Model): #TODO: get avatar from details is_updated = True + print("payee_details:", payee_details) + print("is_updated:", is_updated) if not self.details.get('application_name'): + print('update application') application_details = get_application_details(self.application_id) + print('application_details:', application_details) try: self.details['application_name'] = application_details.name # TODO: get avatar from details is_updated = True except Exception as e: - pass + print("something went wrong") + print(e) if is_updated: + print('update details') self.save() From 410b113bd671b626372385b74f278846908867b0 Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Wed, 18 Jun 2025 11:57:51 +0330 Subject: [PATCH 5/5] pring log --- utils/accounts_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/accounts_client.py b/utils/accounts_client.py index b584285..ecf427c 100644 --- a/utils/accounts_client.py +++ b/utils/accounts_client.py @@ -46,7 +46,8 @@ def login_as_client_credentials(): def get_client(): access_token = login_as_client_credentials()['access_token'] - client = AuthenticatedClient(base_url="https://accounts.gooyal.com", token=access_token) + # TODO: url + client = AuthenticatedClient(base_url="http://accounts:8000", token=access_token) return client