add endpoint create bonus

This commit is contained in:
2025-12-07 14:52:40 +05:00
parent 38f6b43718
commit f720b51c60
3 changed files with 49 additions and 1 deletions

View File

@ -10,6 +10,37 @@ bonus_types_collection = db.bonus_types
user_bonuses_collection = db.user_bonuses
class BonusService:
async def create_bonus_type(self, bonus_data):
"""Создание нового типа бонуса"""
bonus_id = str(uuid.uuid4())
bonus = {
"id": bonus_id,
"name": bonus_data.name,
"description": bonus_data.description,
"effect_type": bonus_data.effect_type,
"base_effect_value": bonus_data.base_effect_value,
"effect_increment": bonus_data.effect_increment,
"price": bonus_data.price,
"upgrade_price": bonus_data.upgrade_price,
"duration": bonus_data.duration,
"max_level": bonus_data.max_level
}
# Проверка на дубликат имени
existing = await bonus_types_collection.find_one({"name": bonus_data.name})
if existing:
raise HTTPException(status_code=400, detail="Бонус с таким именем уже существует")
await bonus_types_collection.insert_one(bonus)
return {
"status": "success",
"message": "Тип бонуса успешно создан",
"bonus_id": bonus_id
}
async def get_user_active_effects(self, username: str):
"""Получить активные эффекты пользователя для плагина"""
from app.db.database import users_collection