from typing import List from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.ext.asyncio import AsyncSession from app.model.transaction import Transaction as TransactionModel from app.schema.index import TransactionResponse from app.engine.postgresdb import get_db_session transaction_router = r = APIRouter(prefix="/api/v1/transactions", tags=["transactions"]) @r.get( "/{user_id}", response_model=List[TransactionResponse], responses={ 200: {"description": "New user created"}, 400: {"description": "Bad request"}, 204: {"description": "No content"}, 500: {"description": "Internal server error"}, }, ) async def get_transactions(user_id: int, db: AsyncSession = Depends(get_db_session)): """ Retrieve all transactions. """ result = await TransactionModel.get_by_user(db, user_id) all_rows = result.all() if len(all_rows) == 0: raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No transactions found for this user") return all_rows