Files
popa_minecraft_launcher_api/app/api/marketplace.py
DIKER0K 1ae08de28b
All checks were successful
Build and Deploy / deploy (push) Successful in 22s
add: endpoints for cancel and edit price item
2025-07-21 22:21:39 +05:00

83 lines
3.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import APIRouter, Query, Body
from typing import Optional
from app.models.marketplace import BuyItemRequest
router = APIRouter(
prefix="/api/marketplace",
tags=["Marketplace"]
)
@router.get("/items")
async def get_marketplace_items(
server_ip: Optional[str] = None,
page: int = Query(1, ge=1),
limit: int = Query(20, ge=1, le=100)
):
"""Получить список предметов на торговой площадке"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().list_items(server_ip, page, limit)
@router.get("/items/{item_id}")
async def get_marketplace_item(item_id: str):
"""Получить информацию о конкретном предмете"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().get_item(item_id)
@router.post("/items/sell")
async def sell_item(
username: str = Body(...),
slot_index: int = Body(...),
amount: int = Body(...),
price: int = Body(...),
server_ip: str = Body(...)
):
"""Выставить предмет на продажу"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().add_item(username, slot_index, amount, price, server_ip)
@router.post("/items/buy/{item_id}")
async def buy_item(
item_id: str,
request: BuyItemRequest
):
"""Купить предмет"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().buy_item(request.username, item_id)
@router.get("/operations")
async def get_marketplace_operations(server_ip: str):
"""Получить список операций для выполнения на сервере"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().get_pending_operations(server_ip)
@router.post("/operations/confirm")
async def confirm_marketplace_operation(data: dict):
"""Подтвердить выполнение операции"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().confirm_operation(data["operation_id"], data.get("status"), data.get("error"))
@router.post("/items/details")
async def submit_item_details(data: dict):
"""Получить подробные данные о предмете"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().update_item_details(data["operation_id"], data["item_data"])
@router.delete("/items/{item_id}")
async def cancel_item_sale(
item_id: str,
username: str = Query(...)
):
"""Снять предмет с продажи"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().cancel_item_sale(username, item_id)
@router.put("/items/{item_id}/price")
async def update_item_price(
item_id: str,
new_price: int = Body(..., gt=0),
username: str = Body(...)
):
"""Обновить цену предмета на торговой площадке"""
from app.services.marketplace import MarketplaceService
return await MarketplaceService().update_item_price(username, item_id, new_price)