Files
popa_minecraft_launcher_api/app/api/store.py

62 lines
2.4 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, UploadFile, File, Form, Depends, HTTPException
from app.services.store_cape import StoreCapeService
from app.models.cape import CapeStoreUpdate, CapePurchase
from typing import Optional
router = APIRouter(
prefix="/store",
tags=["Store"]
)
store_cape_service = StoreCapeService()
@router.get("/capes")
async def get_all_capes():
"""Получение списка всех плащей в магазине"""
return await store_cape_service.get_all_capes()
@router.get("/capes/{cape_id}")
async def get_cape_by_id(cape_id: str):
"""Получение плаща по ID"""
return await store_cape_service.get_cape_by_id(cape_id)
@router.post("/capes")
async def add_cape(
name: str = Form(...),
description: str = Form(...),
price: int = Form(...),
cape_file: UploadFile = File(...)
):
"""Добавление нового плаща в магазин"""
return await store_cape_service.add_cape(name, description, price, cape_file)
@router.put("/capes/{cape_id}")
async def update_cape(cape_id: str, update_data: CapeStoreUpdate):
"""Обновление информации о плаще"""
return await store_cape_service.update_cape(cape_id, update_data)
@router.delete("/capes/{cape_id}")
async def delete_cape(cape_id: str):
"""Удаление плаща из магазина"""
return await store_cape_service.delete_cape(cape_id)
@router.post("/purchase/cape")
async def purchase_cape(username: str, cape_id: str):
"""Покупка плаща пользователем"""
return await store_cape_service.purchase_cape(username, cape_id)
@router.get("/user/{username}/capes")
async def get_user_purchased_capes(username: str):
"""Получение всех приобретенных плащей пользователя"""
return await store_cape_service.get_user_purchased_capes(username)
@router.post("/user/{username}/capes/activate/{cape_id}")
async def activate_purchased_cape(username: str, cape_id: str):
"""Активация приобретенного плаща"""
return await store_cape_service.activate_purchased_cape(username, cape_id)
@router.post("/user/{username}/capes/deactivate/{cape_id}")
async def deactivate_purchased_cape(username: str, cape_id: str):
"""Деактивация приобретенного плаща"""
return await store_cape_service.deactivate_purchased_cape(username, cape_id)