diff --git a/src/main/payments/repository/PaymentsRepository.py b/src/main/payments/repository/PaymentsRepository.py index c78d70c..a028b5a 100644 --- a/src/main/payments/repository/PaymentsRepository.py +++ b/src/main/payments/repository/PaymentsRepository.py @@ -1,5 +1,6 @@ from pymongo import MongoClient from src.main.config.mongodb import get_mongo_client +from bson import ObjectId class PaymentsRepository: def __init__(self): @@ -7,6 +8,7 @@ def __init__(self): 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 지갑 정보 조회 @@ -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}, diff --git a/src/main/payments/service/PaymentsService.py b/src/main/payments/service/PaymentsService.py index 92f1179..728132c 100644 --- a/src/main/payments/service/PaymentsService.py +++ b/src/main/payments/service/PaymentsService.py @@ -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"]