Files
popa_minecraft_launcher_api/app/api/marketplace.py

46 lines
1.6 KiB
Python
Raw 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)