Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/main/payments/repository/PaymentsRepository.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from pymongo import MongoClient
from src.main.config.mongodb import get_mongo_client
from bson import ObjectId

class PaymentsRepository:
def __init__(self):
client: MongoClient = get_mongo_client()
self.db = client["xrpedia-data"]
self.wallets_collection = self.db["wallets"]
self.document_collection = self.db["document_collection"]
self.files_collection = self.db["files"]
self.transactions_collection = self.db["transactions"]

# MongoDB에서 user_id 기반으로 XRPL 지갑 정보 조회
Expand All @@ -15,12 +17,32 @@ def get_user_wallet(self, user_id: str):

# MongoDB에서 파일 정보 전체 조회 (price + owner_id 포함)
def get_file_info(self, file_id: str):
return self.document_collection.find_one(
try:
file_object_id = ObjectId(file_id)
except Exception as e:
print(f"[ERROR] file_id를 ObjectId로 변환할 수 없음: {e}")
return None

file = self.files_collection.find_one(
{"_id": file_object_id},
{"_id": 0, "owner_id": 1}
)

if not file:
print("[WARN] files_collection에서 파일 정보 못 찾음")
return None

doc = self.document_collection.find_one(
{"file_id": file_id},
{"_id": 0, "price": 1, "uploader_id": 1}
{"_id": 0, "price": 1}
)

# MongoDB에서 파일 가격 조회

if not doc:
print("[WARN] document_collection에서 파일 정보 못 찾음")
return None

return {**doc, **file}

def get_file_price(self, file_id: str):
file_info = self.document_collection.find_one(
{"file_id": file_id},
Expand Down
4 changes: 2 additions & 2 deletions src/main/payments/service/PaymentsService.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def request_payment(self, user_id: str, file_id: str):
return HTTPException(status_code=404, detail="파일 정보 없음")

file_price = file_info["price"]
seller_id = file_info["uploader_id"]
seller_id = file_info["owner_id"]

# 판매자의 지갑 주소 가져오기
receiver_wallet_address = self.payments_repository.get_user_wallet(seller_id)
if not receiver_wallet_address:
return HTTPException(status_cod=404, detail="판매자의 XRPL 지갑 없음")
return HTTPException(status_code=404, detail="판매자의 XRPL 지갑 없음")

receiver_wallet_address = receiver_wallet_address["address"]

Expand Down