feat: add create request
This commit is contained in:
@@ -54,6 +54,54 @@ class GetPurchaseRequestCommand:
|
||||
return await self._unit_of_work.purchase_request_repository.get_by_id(request_id)
|
||||
|
||||
|
||||
class CreatePurchaseRequestCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._logger = logger
|
||||
|
||||
@transactional
|
||||
async def __call__(
|
||||
self,
|
||||
*,
|
||||
organization_id: str,
|
||||
usdt_amount: Decimal,
|
||||
status: str = 'submitted',
|
||||
rub_amount: Decimal | None = None,
|
||||
exchange_rate: Decimal | None = None,
|
||||
service_fee_percent: Decimal | None = None,
|
||||
comment: str | None = None,
|
||||
admin_comment: str | None = None,
|
||||
target_wallet_chain: str | None = 'ETH',
|
||||
target_wallet_address: str | None = None,
|
||||
tx_hash: str | None = None,
|
||||
assigned_to: str | None = None,
|
||||
) -> PurchaseRequestEntity:
|
||||
if status not in VALID_STATUSES:
|
||||
raise ApplicationException(status_code=400, message='Invalid status')
|
||||
|
||||
await self._unit_of_work.legal_entity_repository.get_by_id(organization_id)
|
||||
values: dict[str, Any] = {
|
||||
'organization_id': organization_id,
|
||||
'status': status,
|
||||
'usdt_amount': usdt_amount,
|
||||
'rub_amount': rub_amount,
|
||||
'exchange_rate': exchange_rate,
|
||||
'service_fee_percent': service_fee_percent,
|
||||
'comment': comment,
|
||||
'admin_comment': admin_comment,
|
||||
'target_wallet_chain': target_wallet_chain,
|
||||
'target_wallet_address': target_wallet_address,
|
||||
'tx_hash': tx_hash,
|
||||
'assigned_to': assigned_to,
|
||||
}
|
||||
if status == 'completed':
|
||||
values['completed_at'] = datetime.now(timezone.utc)
|
||||
|
||||
created = await self._unit_of_work.purchase_request_repository.create(values)
|
||||
self._logger.info(f'Purchase request created id={created.id} org={organization_id}')
|
||||
return created
|
||||
|
||||
|
||||
class UpdatePurchaseRequestStatusCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
|
||||
Reference in New Issue
Block a user