
- 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
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from sqlalchemy import Column, Integer, String, Float, ForeignKey, DateTime, Enum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import enum
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class AccountType(str, enum.Enum):
|
|
SAVINGS = "savings"
|
|
CHECKING = "checking"
|
|
INVESTMENT = "investment"
|
|
|
|
|
|
class Account(Base):
|
|
__tablename__ = "accounts"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
account_number = Column(String, unique=True, index=True, nullable=False)
|
|
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
account_type = Column(Enum(AccountType), nullable=False)
|
|
balance = Column(Float, default=0.0, nullable=False)
|
|
currency = Column(String, default="USD", nullable=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
owner = relationship("User", back_populates="accounts")
|
|
sent_transactions = relationship(
|
|
"Transaction",
|
|
foreign_keys="[Transaction.sender_account_id]",
|
|
back_populates="sender_account"
|
|
)
|
|
received_transactions = relationship(
|
|
"Transaction",
|
|
foreign_keys="[Transaction.receiver_account_id]",
|
|
back_populates="receiver_account"
|
|
) |