Skip to content

Commit

Permalink
Merge branch 'myeclpay' of https://github.com/aeecleclair/Hyperion in…
Browse files Browse the repository at this point in the history
…to myeclpay
  • Loading branch information
maximeroucher committed Nov 17, 2024
2 parents 91add36 + eeb0c61 commit 47f1137
Show file tree
Hide file tree
Showing 6 changed files with 737 additions and 16 deletions.
109 changes: 108 additions & 1 deletion app/core/myeclpay/cruds_myeclpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,82 @@
from datetime import datetime
from uuid import UUID

from sqlalchemy import or_, select, update
from sqlalchemy import delete, or_, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

from app.core.myeclpay import models_myeclpay
from app.core.myeclpay.types_myeclpay import (
TransactionStatus,
TransactionType,
WalletDeviceStatus,
WalletType,
)


async def create_store(
store: models_myeclpay.Store,
db: AsyncSession,
) -> None:
db.add(store)


async def create_seller(
user_id: str,
store_id: UUID,
can_bank: bool,
can_see_historic: bool,
can_cancel: bool,
can_manage_sellers: bool,
store_admin: bool,
db: AsyncSession,
) -> None:
wallet = models_myeclpay.Seller(
user_id=user_id,
store_id=store_id,
can_bank=can_bank,
can_see_historic=can_see_historic,
can_cancel=can_cancel,
can_manage_sellers=can_manage_sellers,
store_admin=store_admin,
)
db.add(wallet)


async def get_admin_sellers(
store_id: UUID,
db: AsyncSession,
) -> Sequence[models_myeclpay.Seller]:
result = await db.execute(
select(models_myeclpay.Seller).where(
models_myeclpay.Seller.store_id == store_id,
models_myeclpay.Seller.store_admin.is_(True),
),
)
return result.scalars().all()


async def get_seller(
seller_id: UUID,
db: AsyncSession,
) -> models_myeclpay.Seller | None:
result = await db.execute(
select(models_myeclpay.Seller).where(
models_myeclpay.Seller.id == seller_id,
),
)
return result.scalars().first()


async def delete_seller(
seller_id: UUID,
db: AsyncSession,
) -> models_myeclpay.Seller | None:
await db.execute(
delete(models_myeclpay.Seller).where(models_myeclpay.Seller.id == seller_id),
)


async def create_wallet(
wallet_id: UUID,
wallet_type: WalletType,
Expand Down Expand Up @@ -52,6 +116,49 @@ async def get_wallet_device(
return result.scalars().first()


async def get_wallet_devices_by_wallet_id(
wallet_id: UUID,
db: AsyncSession,
) -> Sequence[models_myeclpay.WalletDevice]:
result = await db.execute(
select(models_myeclpay.WalletDevice).where(
models_myeclpay.WalletDevice.wallet_id == wallet_id,
),
)
return result.scalars().all()


async def get_wallet_device_by_activation_token(
activation_token: str,
db: AsyncSession,
) -> models_myeclpay.WalletDevice | None:
result = await db.execute(
select(models_myeclpay.WalletDevice).where(
models_myeclpay.WalletDevice.activation_token == activation_token,
),
)
return result.scalars().first()


async def create_wallet_device(
wallet_device: models_myeclpay.WalletDevice,
db: AsyncSession,
) -> None:
db.add(wallet_device)


async def update_wallet_device_status(
wallet_device_id: UUID,
status: WalletDeviceStatus,
db: AsyncSession,
) -> None:
await db.execute(
update(models_myeclpay.WalletDevice)
.where(models_myeclpay.WalletDevice.id == wallet_device_id)
.values(status=status),
)


async def increment_wallet_balance(
wallet_id: UUID,
amount: int,
Expand Down
Loading

0 comments on commit 47f1137

Please sign in to comment.