add endpoint create bonus
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user