diff --git a/app/crud.py b/app/crud.py index ce51659..1279b92 100644 --- a/app/crud.py +++ b/app/crud.py @@ -1,11 +1,21 @@ from sqlalchemy.orm import Session from app import models +from typing import List -def get_customers(db: Session): +# ---- Customers ---- +def get_customers(db: Session) -> List[models.Customer]: return db.query(models.Customer).all() -def get_accounts(db: Session): - return db.query(models.Account).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() -def get_transactions(db: Session): - return db.query(models.Transactions).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()