Praneeth Yerrapragada commited on
Commit
e130ddf
1 Parent(s): daca853
Files changed (1) hide show
  1. app/api/routers/transaction.py +6 -24
app/api/routers/transaction.py CHANGED
@@ -11,7 +11,7 @@ transaction_router = r = APIRouter(prefix="/api/v1/transactions", tags=["transac
11
 
12
  @r.get(
13
  "/{user_id}",
14
- # response_model=List[TransactionResponse],
15
  responses={
16
  200: {"description": "New user created"},
17
  400: {"description": "Bad request"},
@@ -23,26 +23,8 @@ async def get_transactions(user_id: int, db: AsyncSession = Depends(get_db_sessi
23
  """
24
  Retrieve all transactions.
25
  """
26
- # result = await TransactionModel.get_by_user(db, user_id)
27
- # all_rows = result.all()
28
- # if len(all_rows) == 0:
29
- # raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No transactions found for this user")
30
- # return all_rows
31
-
32
- data_dir = os.path.abspath("data/tx_data/input")
33
- file_path = os.path.join(data_dir, f"transactions_2024.csv")
34
-
35
- if os.path.exists(file_path):
36
- with open(file_path, "r") as f:
37
- lines = f.readlines()
38
- results = []
39
- for line in lines:
40
- line_split = line.strip().split(",")
41
- result = {
42
- "transaction_date": line_split[0],
43
- "name_description": line_split[1],
44
- "type": line_split[2],
45
- "amount": line_split[3],
46
- }
47
- results.append(result)
48
- return results
 
11
 
12
  @r.get(
13
  "/{user_id}",
14
+ response_model=List[TransactionResponse],
15
  responses={
16
  200: {"description": "New user created"},
17
  400: {"description": "Bad request"},
 
23
  """
24
  Retrieve all transactions.
25
  """
26
+ result = await TransactionModel.get_by_user(db, user_id)
27
+ all_rows = result.all()
28
+ if len(all_rows) == 0:
29
+ raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No transactions found for this user")
30
+ return all_rows