Skip to content

Commit 1331223

Browse files
Full s3 logger (#719)
### Description Please explain the changes you made here. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing - [ ] Extended the documentation, if necessary --------- Co-authored-by: armanddidierjean <[email protected]>
1 parent 817c4e2 commit 1331223

20 files changed

+586
-156
lines changed

.env.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ MYECLPAY_MAXIMUM_WALLET_BALANCE: int | None
6868
#MYECLPAY_DATA_VERIFIER_ACCESS_TOKEN = ""
6969

7070
# S3 configuration for file storage
71-
#S3_MYECLPAY_LOGS_BUCKET_NAME = "hyperion"
71+
#S3_BUCKET_NAME = "hyperion"
7272
#S3_ACCESS_KEY_ID = "realaccesskey"
7373
#S3_SECRET_ACCESS_KEY = "realsecretkey"
7474

app/core/core_endpoints/cruds_core.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Sequence
2+
from datetime import datetime
23

3-
from sqlalchemy import delete, select
4+
from sqlalchemy import delete, func, select, text
45
from sqlalchemy.ext.asyncio import AsyncSession
56

67
from app.core.core_endpoints import models_core
@@ -169,3 +170,19 @@ async def delete_core_data_crud(
169170
),
170171
)
171172
await db.flush()
173+
174+
175+
async def start_isolation_mode(
176+
db: AsyncSession,
177+
) -> datetime:
178+
"""
179+
Set the transaction in isolation mode.
180+
It ensures that the transaction will not see any changes made by other transactions
181+
until it is committed or rolled back.
182+
Thus, all subsequent queries in this transaction will see the same data as at the time of the transaction start.
183+
"""
184+
await db.execute(text("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"))
185+
now = (await db.execute(select(func.now()))).scalar()
186+
if now is None:
187+
raise ValueError
188+
return now

app/core/myeclpay/cruds_myeclpay.py

Lines changed: 47 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -386,53 +386,13 @@ async def create_wallet(
386386

387387
async def get_wallets(
388388
db: AsyncSession,
389-
) -> Sequence[schemas_myeclpay.Wallet]:
389+
) -> Sequence[schemas_myeclpay.WalletBase]:
390390
result = await db.execute(select(models_myeclpay.Wallet))
391391
return [
392-
schemas_myeclpay.Wallet(
392+
schemas_myeclpay.WalletBase(
393393
id=wallet.id,
394394
type=wallet.type,
395395
balance=wallet.balance,
396-
store=schemas_myeclpay.Store(
397-
id=wallet.store.id,
398-
name=wallet.store.name,
399-
structure_id=wallet.store.structure_id,
400-
structure=schemas_myeclpay.Structure(
401-
id=wallet.store.structure.id,
402-
name=wallet.store.structure.name,
403-
association_membership_id=wallet.store.structure.association_membership_id,
404-
association_membership=schemas_memberships.MembershipSimple(
405-
id=wallet.store.structure.association_membership.id,
406-
name=wallet.store.structure.association_membership.name,
407-
manager_group_id=wallet.store.structure.association_membership.manager_group_id,
408-
)
409-
if wallet.store.structure.association_membership
410-
else None,
411-
manager_user_id=wallet.store.structure.manager_user_id,
412-
manager_user=schemas_users.CoreUserSimple(
413-
id=wallet.store.structure.manager_user.id,
414-
firstname=wallet.store.structure.manager_user.firstname,
415-
name=wallet.store.structure.manager_user.name,
416-
nickname=wallet.store.structure.manager_user.nickname,
417-
account_type=wallet.store.structure.manager_user.account_type,
418-
school_id=wallet.store.structure.manager_user.school_id,
419-
),
420-
),
421-
wallet_id=wallet.id,
422-
)
423-
if wallet.store
424-
else None,
425-
user=schemas_users.CoreUser(
426-
id=wallet.user.id,
427-
firstname=wallet.user.firstname,
428-
name=wallet.user.name,
429-
nickname=wallet.user.nickname,
430-
account_type=wallet.user.account_type,
431-
school_id=wallet.user.school_id,
432-
email=wallet.user.email,
433-
)
434-
if wallet.user
435-
else None,
436396
)
437397
for wallet in result.scalars().all()
438398
]
@@ -582,7 +542,7 @@ async def get_user_payment(
582542

583543

584544
async def create_transaction(
585-
transaction: schemas_myeclpay.Transaction,
545+
transaction: schemas_myeclpay.TransactionBase,
586546
debited_wallet_device_id: UUID,
587547
store_note: str | None,
588548
db: AsyncSession,
@@ -598,6 +558,7 @@ async def create_transaction(
598558
creation=transaction.creation,
599559
status=transaction.status,
600560
store_note=store_note,
561+
qr_code_id=transaction.qr_code_id,
601562
)
602563
db.add(transaction_db)
603564

@@ -651,10 +612,25 @@ async def get_transaction(
651612

652613
async def get_transactions(
653614
db: AsyncSession,
654-
) -> Sequence[schemas_myeclpay.Transaction]:
655-
result = await db.execute(select(models_myeclpay.Transaction))
615+
start_date: datetime | None = None,
616+
end_date: datetime | None = None,
617+
exclude_canceled: bool = False,
618+
) -> Sequence[schemas_myeclpay.TransactionBase]:
619+
result = await db.execute(
620+
select(models_myeclpay.Transaction).where(
621+
models_myeclpay.Transaction.creation >= start_date
622+
if start_date
623+
else and_(True),
624+
models_myeclpay.Transaction.creation <= end_date
625+
if end_date
626+
else and_(True),
627+
models_myeclpay.Transaction.status != TransactionStatus.CANCELED
628+
if exclude_canceled
629+
else and_(True),
630+
),
631+
)
656632
return [
657-
schemas_myeclpay.Transaction(
633+
schemas_myeclpay.TransactionBase(
658634
id=transaction.id,
659635
debited_wallet_id=transaction.debited_wallet_id,
660636
credited_wallet_id=transaction.credited_wallet_id,
@@ -698,8 +674,15 @@ async def get_transactions_by_wallet_id(
698674

699675
async def get_transfers(
700676
db: AsyncSession,
677+
last_checked: datetime | None = None,
701678
) -> Sequence[schemas_myeclpay.Transfer]:
702-
result = await db.execute(select(models_myeclpay.Transfer))
679+
result = await db.execute(
680+
select(models_myeclpay.Transfer).where(
681+
models_myeclpay.Transfer.creation >= last_checked
682+
if last_checked
683+
else and_(True),
684+
),
685+
)
703686
return [
704687
schemas_myeclpay.Transfer(
705688
id=transfer.id,
@@ -780,45 +763,24 @@ async def get_transfer_by_transfer_identifier(
780763

781764
async def get_refunds(
782765
db: AsyncSession,
783-
) -> Sequence[schemas_myeclpay.Refund]:
784-
result = await db.execute(select(models_myeclpay.Refund))
766+
last_checked: datetime | None = None,
767+
) -> Sequence[schemas_myeclpay.RefundBase]:
768+
result = await db.execute(
769+
select(models_myeclpay.Refund).where(
770+
models_myeclpay.Refund.creation >= last_checked
771+
if last_checked
772+
else and_(True),
773+
),
774+
)
785775
return [
786-
schemas_myeclpay.Refund(
776+
schemas_myeclpay.RefundBase(
787777
id=refund.id,
788778
transaction_id=refund.transaction_id,
789779
credited_wallet_id=refund.credited_wallet_id,
790780
debited_wallet_id=refund.debited_wallet_id,
791781
total=refund.total,
792782
creation=refund.creation,
793783
seller_user_id=refund.seller_user_id,
794-
transaction=schemas_myeclpay.Transaction(
795-
id=refund.transaction.id,
796-
debited_wallet_id=refund.transaction.debited_wallet_id,
797-
credited_wallet_id=refund.transaction.credited_wallet_id,
798-
transaction_type=refund.transaction.transaction_type,
799-
seller_user_id=refund.transaction.seller_user_id,
800-
total=refund.transaction.total,
801-
creation=refund.transaction.creation,
802-
status=refund.transaction.status,
803-
),
804-
debited_wallet=schemas_myeclpay.WalletInfo(
805-
id=refund.debited_wallet.id,
806-
type=refund.debited_wallet.type,
807-
owner_name=refund.debited_wallet.store.name
808-
if refund.debited_wallet.store
809-
else refund.debited_wallet.user.full_name
810-
if refund.debited_wallet.user
811-
else None,
812-
),
813-
credited_wallet=schemas_myeclpay.WalletInfo(
814-
id=refund.credited_wallet.id,
815-
type=refund.credited_wallet.type,
816-
owner_name=refund.credited_wallet.store.name
817-
if refund.credited_wallet.store
818-
else refund.credited_wallet.user.full_name
819-
if refund.credited_wallet.user
820-
else None,
821-
),
822784
)
823785
for refund in result.scalars().all()
824786
]
@@ -984,11 +946,16 @@ async def get_store(
984946

985947

986948
async def create_used_qrcode(
987-
qr_code_id: UUID,
949+
qr_code: schemas_myeclpay.ScanInfo,
988950
db: AsyncSession,
989951
) -> None:
990952
wallet = models_myeclpay.UsedQRCode(
991-
qr_code_id=qr_code_id,
953+
qr_code_id=qr_code.id,
954+
qr_code_tot=qr_code.tot,
955+
qr_code_iat=qr_code.iat,
956+
qr_code_key=qr_code.key,
957+
qr_code_store=qr_code.store,
958+
signature=qr_code.signature,
992959
)
993960
db.add(wallet)
994961

0 commit comments

Comments
 (0)