69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
from typing import List
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.transaction import Transaction
|
|
from app.schemas.transaction import TransactionCreate, TransactionUpdate
|
|
|
|
|
|
class CRUDTransaction(CRUDBase[Transaction, TransactionCreate, TransactionUpdate]):
|
|
def get_by_user(
|
|
self, db: Session, *, user_id: int, skip: int = 0, limit: int = 100
|
|
) -> List[Transaction]:
|
|
return (
|
|
db.query(Transaction)
|
|
.filter(Transaction.user_id == user_id)
|
|
.order_by(Transaction.created_at.desc())
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_by_wallet(
|
|
self, db: Session, *, wallet_id: int, skip: int = 0, limit: int = 100
|
|
) -> List[Transaction]:
|
|
return (
|
|
db.query(Transaction)
|
|
.filter(Transaction.wallet_id == wallet_id)
|
|
.order_by(Transaction.created_at.desc())
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_by_type(
|
|
self, db: Session, *, transaction_type: str, skip: int = 0, limit: int = 100
|
|
) -> List[Transaction]:
|
|
return (
|
|
db.query(Transaction)
|
|
.filter(Transaction.transaction_type == transaction_type)
|
|
.order_by(Transaction.created_at.desc())
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_all(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100
|
|
) -> List[Transaction]:
|
|
return (
|
|
db.query(Transaction)
|
|
.order_by(Transaction.created_at.desc())
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
transaction = CRUDTransaction(Transaction)
|
|
|
|
|
|
# Aliases for convenience
|
|
get_transaction = transaction.get
|
|
create_transaction = transaction.create
|
|
update_transaction = transaction.update
|
|
get_transactions_by_user = transaction.get_by_user
|
|
get_transactions_by_wallet = transaction.get_by_wallet
|
|
get_transactions_by_type = transaction.get_by_type
|
|
get_all_transactions = transaction.get_all |