Skip to content

Commit

Permalink
Refactor schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
PSNAppz committed Aug 7, 2024
1 parent 5166bb0 commit ec51c5d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from openg2p_g2p_bridge_example_bank_models.schemas import (
InitiatePaymentPayload,
InitiatorPaymentResponse,
InitiatePaymentResponse,
)
from sqlalchemy.ext.asyncio import async_sessionmaker
from sqlalchemy.future import select
Expand All @@ -31,13 +31,13 @@ def __init__(self, **kwargs):
self.router.add_api_route(
"/initiate_payment",
self.initiate_payment,
response_model=InitiatorPaymentResponse,
response_model=InitiatePaymentResponse,
methods=["POST"],
)

async def initiate_payment(
self, initiate_payment_payloads: List[InitiatePaymentPayload]
) -> InitiatorPaymentResponse:
) -> InitiatePaymentResponse:
_logger.info("Initiating payment")
session_maker = async_sessionmaker(dbengine.get(), expire_on_commit=False)
async with session_maker() as session:
Expand Down Expand Up @@ -65,7 +65,7 @@ async def initiate_payment(
_logger.error(
"Invalid funds block reference or mismatch in details"
)
return InitiatorPaymentResponse(
return InitiatePaymentResponse(
status="failed",
error_message="Invalid funds block reference or mismatch in details",
)
Expand Down Expand Up @@ -101,4 +101,4 @@ async def initiate_payment(
session.add_all(initiate_payment_requests)
await session.commit()
_logger.info("Payment initiated successfully")
return InitiatorPaymentResponse(status="success", error_message="")
return InitiatePaymentResponse(status="success", error_message="")
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from .fund_schemas import (
AccountStatementRequest,
AccountStatementResponse,
from .account import (
BlockFundsRequest,
BlockFundsResponse,
CheckFundRequest,
CheckFundResponse,
)
from .account_statement import (
AccountStatementRequest,
AccountStatementResponse,
)
from .payment_request import (
InitiatePaymentPayload,
InitiatorPaymentResponse,
InitiatePaymentResponse,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import Optional

from pydantic import BaseModel


class CheckFundRequest(BaseModel):
account_number: str
account_currency: str
total_funds_needed: float


class CheckFundResponse(BaseModel):
status: str
account_number: str
has_sufficient_funds: bool
error_message: Optional[str] = None


class BlockFundsRequest(BaseModel):
account_number: str
currency: str
amount: float


class BlockFundsResponse(BaseModel):
status: str
block_reference_no: str
error_message: Optional[str] = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Optional

from pydantic import BaseModel


class AccountStatementRequest(BaseModel):
program_account_number: str


class AccountStatementResponse(BaseModel):
status: str
account_statement_id: Optional[str] = None
error_message: Optional[str] = None
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@
from pydantic import BaseModel


class CheckFundRequest(BaseModel):
account_number: str
account_currency: str
total_funds_needed: float


class CheckFundResponse(BaseModel):
status: str
account_number: str
has_sufficient_funds: bool
error_message: Optional[str] = None


class BlockFundsRequest(BaseModel):
account_number: str
currency: str
amount: float


class BlockFundsResponse(BaseModel):
status: str
block_reference_no: str
error_message: Optional[str] = None


class InitiatePaymentPayload(BaseModel):
payment_reference_number: str
remitting_account: str
Expand Down Expand Up @@ -58,16 +33,6 @@ class InitiatePaymentPayload(BaseModel):
payment_date: str


class InitiatorPaymentResponse(BaseModel):
status: str
error_message: Optional[str] = None


class AccountStatementRequest(BaseModel):
program_account_number: str


class AccountStatementResponse(BaseModel):
class InitiatePaymentResponse(BaseModel):
status: str
account_statement_id: Optional[str] = None
error_message: Optional[str] = None

0 comments on commit ec51c5d

Please sign in to comment.