21 lines
753 B
Python
21 lines
753 B
Python
from sqlalchemy.orm import Session
|
|
from app import models
|
|
from typing import List
|
|
|
|
# ---- Customers ----
|
|
def get_customers(db: Session) -> List[models.Customer]:
|
|
return db.query(models.Customer).all()
|
|
|
|
# ---- Accounts ----
|
|
def get_accounts(db: Session, customer_id: int = None) -> List[models.Account]:
|
|
query = db.query(models.Account)
|
|
if customer_id is not None:
|
|
query = query.filter(models.Account.customer_id == customer_id)
|
|
return query.all()
|
|
|
|
# ---- Transactions ----
|
|
def get_transactions(db: Session, account_id: str = None) -> List[models.Transaction]:
|
|
query = db.query(models.Transaction)
|
|
if account_id is not None:
|
|
query = query.filter(models.Transaction.account_id == account_id)
|
|
return query.all()
|