Spaces:
Sleeping
Sleeping
File size: 1,064 Bytes
a4ec216 114f9f7 a4ec216 114f9f7 a4ec216 114f9f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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
|