Update app/crud.py
This commit is contained in:
parent
d8ef3694aa
commit
53ab4ffd5e
1 changed files with 15 additions and 5 deletions
20
app/crud.py
20
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue