Spaces:
Build error
Build error
Commit
·
18c1f85
1
Parent(s):
1157bd1
Without database
Browse files- app/crud/transaction.py +0 -24
app/crud/transaction.py
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
from app.db.database import db
|
2 |
-
from app.schemas.user import TransactionResponse
|
3 |
-
from bson.objectid import ObjectId
|
4 |
-
from datetime import datetime
|
5 |
-
|
6 |
-
async def record_transaction(user_id: str, amount: float, description: str):
|
7 |
-
transaction = {
|
8 |
-
"user_id": ObjectId(user_id),
|
9 |
-
"amount": amount,
|
10 |
-
"description": description,
|
11 |
-
"timestamp": datetime.utcnow()
|
12 |
-
}
|
13 |
-
result = await db.transactions.insert_one(transaction)
|
14 |
-
transaction["_id"] = result.inserted_id
|
15 |
-
transaction["id"] = str(transaction.pop("_id"))
|
16 |
-
return transaction
|
17 |
-
|
18 |
-
async def get_user_transactions(user_id: str):
|
19 |
-
cursor = db.transactions.find({"user_id": ObjectId(user_id)})
|
20 |
-
transactions = []
|
21 |
-
async for transaction in cursor:
|
22 |
-
transaction["id"] = str(transaction.pop("_id"))
|
23 |
-
transactions.append(transaction)
|
24 |
-
return transactions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|