1+ from pymongo import MongoClient
2+ from src .main .config .mongodb import get_mongo_client
3+
4+ class PaymentsRepository :
5+ def __init__ (self ):
6+ client : MongoClient = get_mongo_client ()
7+ self .db = client ["xrpedia-data" ]
8+ self .wallets_collection = self .db ["wallets" ]
9+ self .document_collection = self .db ["document_collection" ]
10+ self .transactions_collection = self .db ["transactions" ]
11+
12+ # MongoDB에서 user_id 기반으로 XRPL 지갑 정보 조회
13+ def get_user_wallet (self , user_id : str ):
14+ return self .wallets_collection .find_one ({"user_id" : user_id }, {"_id" : 0 , "address" : 1 , "seed" : 1 })
15+
16+ # MongoDB에서 파일 정보 전체 조회 (price + owner_id 포함)
17+ def get_file_info (self , file_id : str ):
18+ return self .document_collection .find_one (
19+ {"file_id" : file_id },
20+ {"_id" : 0 , "price" : 1 , "uploader_id" : 1 }
21+ )
22+
23+ # MongoDB에서 파일 가격 조회
24+ def get_file_price (self , file_id : str ):
25+ file_info = self .document_collection .find_one (
26+ {"file_id" : file_id },
27+ {"_id" : 0 , "price" : 1 }
28+ )
29+ return file_info ["price" ] if file_info else None
30+
31+ def get_user_profile (self , user_id : str ):
32+ return self .wallets_collection .find_one (
33+ {"user_id" : user_id },
34+ {"_id" : 0 , "profile" : 1 }
35+ )
36+
37+ def update_user_rlusd (self , user_id : str , new_rlusd : int ):
38+ self .wallets_collection .update_one (
39+ {"user_id" : user_id },
40+ {"$set" : {"rlusd" : new_rlusd }}
41+ )
42+
43+ def is_transaction_exist (self , user_id : str , file_id : str ):
44+ print (f"Checking if transaction exists for user_id: { user_id } , file_id: { file_id } " )
45+ transaction = self .transactions_collection .find_one (
46+ {"user_id" : user_id , "file_id" : file_id }
47+ )
48+ if transaction :
49+ print (f"Transaction found: { transaction } " )
50+ else :
51+ print ("Transaction not found" )
52+ return transaction is not None
53+
54+ def save_transaction (self , tx_data : dict ):
55+ print (f"Saving transaction: { tx_data } " )
56+ self .transactions_collection .insert_one (tx_data )
0 commit comments