
- Set up project structure with FastAPI - Implement user and account management - Add send and receive money functionality - Set up transaction processing system - Add JWT authentication - Configure SQLAlchemy with SQLite - Set up Alembic for database migrations - Create comprehensive API documentation
79 lines
1.9 KiB
Python
79 lines
1.9 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
|
|
class TransactionType(str, Enum):
|
|
DEPOSIT = "deposit"
|
|
WITHDRAWAL = "withdrawal"
|
|
TRANSFER = "transfer"
|
|
|
|
|
|
class TransactionStatus(str, Enum):
|
|
PENDING = "pending"
|
|
COMPLETED = "completed"
|
|
FAILED = "failed"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class TransactionBase(BaseModel):
|
|
amount: float = Field(..., gt=0)
|
|
currency: str = "USD"
|
|
description: Optional[str] = None
|
|
|
|
|
|
class DepositCreate(TransactionBase):
|
|
"""Request model for creating a deposit"""
|
|
account_id: int
|
|
|
|
|
|
class WithdrawalCreate(TransactionBase):
|
|
"""Request model for creating a withdrawal"""
|
|
account_id: int
|
|
|
|
|
|
class TransferCreate(TransactionBase):
|
|
"""Request model for creating a transfer between accounts"""
|
|
sender_account_id: int
|
|
receiver_account_id: int
|
|
|
|
|
|
class ReceiveMoneyCreate(TransactionBase):
|
|
"""Request model for receiving money from external source"""
|
|
receiver_account_id: int
|
|
external_sender_info: str
|
|
|
|
|
|
class SendMoneyCreate(TransactionBase):
|
|
"""Request model for sending money to external destination"""
|
|
sender_account_id: int
|
|
external_receiver_info: str
|
|
|
|
|
|
class TransactionUpdate(BaseModel):
|
|
"""Request model for updating a transaction"""
|
|
status: Optional[TransactionStatus] = None
|
|
description: Optional[str] = None
|
|
|
|
|
|
class TransactionInDBBase(TransactionBase):
|
|
id: int
|
|
transaction_reference: str
|
|
sender_id: Optional[int] = None
|
|
sender_account_id: Optional[int] = None
|
|
receiver_id: Optional[int] = None
|
|
receiver_account_id: Optional[int] = None
|
|
transaction_type: TransactionType
|
|
status: TransactionStatus
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
completed_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Transaction(TransactionInDBBase):
|
|
"""Response model for transaction data"""
|
|
pass |