init
This commit is contained in:
87
src/presentation/schemas/mappers.py
Normal file
87
src/presentation/schemas/mappers.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from src.application.domain.entities.organization import (
|
||||
LegalEntityEntity,
|
||||
OrganizationDocumentEntity,
|
||||
OrganizationWalletEntity,
|
||||
PurchaseRequestEntity,
|
||||
)
|
||||
from src.presentation.schemas.organization import (
|
||||
DocumentResponse,
|
||||
OrganizationResponse,
|
||||
PurchaseRequestResponse,
|
||||
WalletResponse,
|
||||
)
|
||||
|
||||
|
||||
def organization_to_response(entity: LegalEntityEntity) -> OrganizationResponse:
|
||||
return OrganizationResponse(
|
||||
id=entity.id,
|
||||
user_id=entity.user_id,
|
||||
name=entity.name,
|
||||
short_name=entity.short_name,
|
||||
inn=entity.inn,
|
||||
ogrn=entity.ogrn,
|
||||
kpp=entity.kpp,
|
||||
legal_address=entity.legal_address,
|
||||
actual_address=entity.actual_address,
|
||||
bank_details=entity.bank_details,
|
||||
contact_person=entity.contact_person,
|
||||
contact_phone=entity.contact_phone,
|
||||
status=entity.status,
|
||||
kyc_verified=entity.kyc_verified,
|
||||
kyc_verified_at=entity.kyc_verified_at.isoformat() if entity.kyc_verified_at else None,
|
||||
has_wallets=bool(entity.encrypted_mnemonic),
|
||||
created_by=entity.created_by,
|
||||
created_at=entity.created_at.isoformat() if entity.created_at else None,
|
||||
updated_at=entity.updated_at.isoformat() if entity.updated_at else None,
|
||||
)
|
||||
|
||||
|
||||
def wallet_to_response(entity: OrganizationWalletEntity) -> WalletResponse:
|
||||
return WalletResponse(
|
||||
id=entity.id,
|
||||
chain=entity.chain,
|
||||
address=entity.address,
|
||||
derivation_path=entity.derivation_path,
|
||||
created_at=entity.created_at.isoformat() if entity.created_at else None,
|
||||
)
|
||||
|
||||
|
||||
def document_to_response(
|
||||
entity: OrganizationDocumentEntity,
|
||||
*,
|
||||
download_url: str | None = None,
|
||||
) -> DocumentResponse:
|
||||
return DocumentResponse(
|
||||
id=entity.id,
|
||||
organization_id=entity.organization_id,
|
||||
document_type=entity.document_type,
|
||||
file_name=entity.file_name,
|
||||
content_type=entity.content_type,
|
||||
file_size_bytes=entity.file_size_bytes,
|
||||
uploaded_by=entity.uploaded_by,
|
||||
created_at=entity.created_at.isoformat() if entity.created_at else None,
|
||||
download_url=download_url,
|
||||
)
|
||||
|
||||
|
||||
def purchase_request_to_response(entity: PurchaseRequestEntity) -> PurchaseRequestResponse:
|
||||
return PurchaseRequestResponse(
|
||||
id=entity.id,
|
||||
organization_id=entity.organization_id,
|
||||
status=entity.status,
|
||||
usdt_amount=str(entity.usdt_amount),
|
||||
rub_amount=str(entity.rub_amount) if entity.rub_amount is not None else None,
|
||||
exchange_rate=str(entity.exchange_rate) if entity.exchange_rate is not None else None,
|
||||
service_fee_percent=str(entity.service_fee_percent) if entity.service_fee_percent is not None else None,
|
||||
comment=entity.comment,
|
||||
admin_comment=entity.admin_comment,
|
||||
target_wallet_chain=entity.target_wallet_chain,
|
||||
target_wallet_address=entity.target_wallet_address,
|
||||
tx_hash=entity.tx_hash,
|
||||
assigned_to=entity.assigned_to,
|
||||
created_at=entity.created_at.isoformat() if entity.created_at else None,
|
||||
updated_at=entity.updated_at.isoformat() if entity.updated_at else None,
|
||||
completed_at=entity.completed_at.isoformat() if entity.completed_at else None,
|
||||
)
|
||||
Reference in New Issue
Block a user