refactor: swap currency
This commit is contained in:
@@ -26,7 +26,7 @@ class CreatePurchaseRequestCommand:
|
||||
self,
|
||||
user_id: str,
|
||||
*,
|
||||
usdt_amount: Decimal,
|
||||
rub_amount: Decimal,
|
||||
comment: str | None = None,
|
||||
target_wallet_chain: str | None = None,
|
||||
target_wallet_address: str | None = None,
|
||||
@@ -34,7 +34,7 @@ class CreatePurchaseRequestCommand:
|
||||
legal_entity = await require_legal_entity(user_id, self._unit_of_work)
|
||||
item = await self._unit_of_work.purchase_request_repository.create(
|
||||
organization_id=legal_entity.id,
|
||||
usdt_amount=usdt_amount,
|
||||
rub_amount=rub_amount,
|
||||
comment=comment,
|
||||
target_wallet_chain=target_wallet_chain,
|
||||
target_wallet_address=target_wallet_address,
|
||||
@@ -52,29 +52,29 @@ class CreatePurchaseRequestCommand:
|
||||
}
|
||||
payload = {
|
||||
'id_client': legal_entity.id,
|
||||
'usdt_amount': usdt_amount,
|
||||
'rub_amount': rub_amount,
|
||||
}
|
||||
message = {
|
||||
'event': 'purchase_created',
|
||||
'payload': payload,
|
||||
'metadata': metadata,
|
||||
}
|
||||
self._logger.info(f'Create purchase request for organization_id={legal_entity.id } with usdt_amount={usdt_amount}')
|
||||
try:
|
||||
await self._messanger.publish_to_queue(
|
||||
queue=settings.RABBIT_TELEGRAM_NOTIFY_QUEUE,
|
||||
message=message,
|
||||
persist=True,
|
||||
correlation_id=trace_id,
|
||||
message_id=message_id,
|
||||
headers={'trace_id': trace_id} if trace_id else None,
|
||||
)
|
||||
except Exception as exception:
|
||||
self._logger.error(f'Failed to publish purchase request notification for organization_id={legal_entity.id}: {str(exception)}')
|
||||
raise ApplicationException(503, 'Temporary error. Please try again.')
|
||||
self._logger.info(f'Create purchase request for organization_id={legal_entity.id } with rub_amount={rub_amount}')
|
||||
# try:
|
||||
# await self._messanger.publish_to_queue(
|
||||
# queue=settings.RABBIT_TELEGRAM_NOTIFY_QUEUE,
|
||||
# message=message,
|
||||
# persist=True,
|
||||
# correlation_id=trace_id,
|
||||
# message_id=message_id,
|
||||
# headers={'trace_id': trace_id} if trace_id else None,
|
||||
# )
|
||||
# except Exception as exception:
|
||||
# self._logger.error(f'Failed to publish purchase request notification for organization_id={legal_entity.id}: {str(exception)}')
|
||||
# raise ApplicationException(503, 'Temporary error. Please try again.')
|
||||
|
||||
self._logger.info(f'Purchase request created id= organization_id={legal_entity.id }')
|
||||
return item
|
||||
# self._logger.info(f'Purchase request created id= organization_id={legal_entity.id }')
|
||||
# return item
|
||||
|
||||
|
||||
class ListPurchaseRequestsCommand:
|
||||
|
||||
@@ -10,8 +10,8 @@ class PurchaseRequestEntity:
|
||||
id: str
|
||||
organization_id: str
|
||||
status: str
|
||||
usdt_amount: Decimal
|
||||
rub_amount: Decimal | None
|
||||
rub_amount: Decimal
|
||||
usdt_amount: Decimal | None
|
||||
exchange_rate: Decimal | None
|
||||
service_fee_percent: Decimal | None
|
||||
comment: str | None
|
||||
|
||||
@@ -20,8 +20,8 @@ class PurchaseRequestModel(Base, UlidPrimaryKeyMixin, AuditTimestampsMixin):
|
||||
index=True,
|
||||
)
|
||||
status: Mapped[str] = mapped_column(String(32), nullable=False, server_default='submitted', default='submitted')
|
||||
usdt_amount: Mapped[Decimal] = mapped_column(Numeric(18, 8), nullable=False)
|
||||
rub_amount: Mapped[Decimal | None] = mapped_column(Numeric(18, 2), nullable=True)
|
||||
rub_amount: Mapped[Decimal] = mapped_column(Numeric(18, 8), nullable=False)
|
||||
usdt_amount: Mapped[Decimal | None] = mapped_column(Numeric(18, 2), nullable=True)
|
||||
exchange_rate: Mapped[Decimal | None] = mapped_column(Numeric(18, 8), nullable=True)
|
||||
service_fee_percent: Mapped[Decimal | None] = mapped_column(Numeric(5, 2), nullable=True)
|
||||
comment: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
|
||||
@@ -49,7 +49,7 @@ class PurchaseRequestRepository(IPurchaseRequestRepository):
|
||||
self,
|
||||
*,
|
||||
organization_id: str,
|
||||
usdt_amount: Decimal,
|
||||
rub_amount: Decimal,
|
||||
comment: str | None,
|
||||
target_wallet_chain: str | None,
|
||||
target_wallet_address: str | None,
|
||||
@@ -59,7 +59,7 @@ class PurchaseRequestRepository(IPurchaseRequestRepository):
|
||||
id=str(ULID()),
|
||||
organization_id=organization_id,
|
||||
status='submitted',
|
||||
usdt_amount=usdt_amount,
|
||||
rub_amount=rub_amount,
|
||||
comment=comment,
|
||||
target_wallet_chain=target_wallet_chain or 'ETH',
|
||||
target_wallet_address=target_wallet_address,
|
||||
|
||||
@@ -33,7 +33,7 @@ async def create_purchase_request(
|
||||
):
|
||||
item = await command(
|
||||
auth.user_id,
|
||||
usdt_amount=body.usdt_amount,
|
||||
rub_amount=body.rub_amount,
|
||||
comment=body.comment,
|
||||
target_wallet_chain=body.target_wallet_chain,
|
||||
target_wallet_address=body.target_wallet_address,
|
||||
@@ -42,17 +42,17 @@ async def create_purchase_request(
|
||||
|
||||
|
||||
@purchase_requests_router.get('', response_model=PurchaseRequestListResponse)
|
||||
@csrf_protect()
|
||||
#@csrf_protect()
|
||||
async def list_purchase_requests(
|
||||
request: Request,
|
||||
status_filter: str | None = Query(default=None, alias='status'),
|
||||
limit: int = Query(default=50, ge=1, le=200),
|
||||
offset: int = Query(default=0, ge=0),
|
||||
auth: AuthContext = Depends(require_access_token),
|
||||
# auth: AuthContext = Depends(require_access_token),
|
||||
command: ListPurchaseRequestsCommand = Depends(get_list_purchase_requests_command),
|
||||
):
|
||||
items, total = await command(
|
||||
auth.user_id,
|
||||
"01KTK377Q4J8XQZ2N544VDAX5Y",
|
||||
status=status_filter,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
|
||||
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CreatePurchaseRequestBody(BaseModel):
|
||||
usdt_amount: Decimal = Field(gt=0)
|
||||
rub_amount: Decimal = Field(gt=0)
|
||||
comment: str | None = None
|
||||
target_wallet_chain: str | None = Field(default='ETH', max_length=16)
|
||||
target_wallet_address: str | None = Field(default=None, max_length=128)
|
||||
@@ -16,8 +16,8 @@ class PurchaseRequestResponse(BaseModel):
|
||||
id: str
|
||||
organization_id: str
|
||||
status: str
|
||||
usdt_amount: str
|
||||
rub_amount: str | None
|
||||
rub_amount: str
|
||||
usdt_amount: str | None
|
||||
exchange_rate: str | None
|
||||
service_fee_percent: str | None
|
||||
comment: str | None
|
||||
|
||||
Reference in New Issue
Block a user