add new enpoints to marketplace

This commit is contained in:
2025-12-13 19:46:44 +05:00
parent d16cbd289b
commit 80a9fbe148
2 changed files with 149 additions and 0 deletions

View File

@ -247,6 +247,42 @@ class MarketplaceService:
"operation_id": operation_id,
"message": "Предмет снят с продажи и будет возвращен в ваш инвентарь"
}
async def list_items_by_seller(
self,
username: str,
server_ip: str = None,
page: int = 1,
limit: int = 20
):
"""Получить товары, выставленные конкретным продавцом"""
query = {
"seller_name": username
}
if server_ip:
query["server_ip"] = server_ip
total = await marketplace_collection.count_documents(query)
items_cursor = (
marketplace_collection
.find(query)
.sort("created_at", -1)
.skip((page - 1) * limit)
.limit(limit)
)
items = await items_cursor.to_list(limit)
serialized_items = [_serialize_mongodb_doc(item) for item in items]
return {
"items": serialized_items,
"total": total,
"page": page,
"pages": (total + limit - 1) // limit
}
async def update_item_price(self, username: str, item_id: str, new_price: int):
"""Обновить цену предмета на торговой площадке"""
@ -276,3 +312,44 @@ class MarketplaceService:
"status": "success",
"message": f"Цена предмета обновлена на {new_price} монет"
}
async def list_operations(
self,
server_ip: str = None,
player_name: str = None,
status: str = None,
op_type: str = None,
page: int = 1,
limit: int = 20
):
"""Получить операции маркетплейса (все или по игроку)"""
query = {}
if server_ip:
query["server_ip"] = server_ip
if player_name:
query["player_name"] = player_name
if status:
query["status"] = status
if op_type:
query["type"] = op_type
total = await marketplace_operations.count_documents(query)
cursor = (
marketplace_operations
.find(query)
.sort("created_at", -1)
.skip((page - 1) * limit)
.limit(limit)
)
ops = await cursor.to_list(limit)
serialized_ops = _serialize_mongodb_doc(ops)
return {
"operations": serialized_ops,
"total": total,
"page": page,
"pages": (total + limit - 1) // limit
}