Praneeth Yerrapragada commited on
Commit
48ab300
1 Parent(s): 4761dd9

chore: fake transaction reponse

Browse files
Files changed (1) hide show
  1. app/api/routers/transaction.py +25 -6
app/api/routers/transaction.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from typing import List
2
  from fastapi import APIRouter, Depends, HTTPException, status
3
  from sqlalchemy.ext.asyncio import AsyncSession
@@ -10,7 +11,7 @@ transaction_router = r = APIRouter(prefix="/api/v1/transactions", tags=["transac
10
 
11
  @r.get(
12
  "/{user_id}",
13
- response_model=List[TransactionResponse],
14
  responses={
15
  200: {"description": "New user created"},
16
  400: {"description": "Bad request"},
@@ -22,8 +23,26 @@ async def get_transactions(user_id: int, db: AsyncSession = Depends(get_db_sessi
22
  """
23
  Retrieve all transactions.
24
  """
25
- result = await TransactionModel.get_by_user(db, user_id)
26
- all_rows = result.all()
27
- if len(all_rows) == 0:
28
- raise HTTPException(status_code=status.HTTP_204_NO_CONTENT, detail="No transactions found for this user")
29
- return all_rows
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  from typing import List
3
  from fastapi import APIRouter, Depends, HTTPException, status
4
  from sqlalchemy.ext.asyncio import AsyncSession
 
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
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