Некоторые поправки что бы всё работало
This commit is contained in:
@@ -129,26 +129,39 @@ async def get_subscriptions(telegram_id: int, database_manager: DatabaseManager
|
||||
logger.info(f"Получение подписок для пользователя: {telegram_id}")
|
||||
try:
|
||||
# Получаем подписки без ограничений или с указанным лимитом
|
||||
subscriptions = await database_manager.get_last_subscriptions(telegram_id=telegram_id)
|
||||
subscription = await database_manager.get_last_subscriptions(telegram_id=telegram_id)
|
||||
|
||||
if not subscriptions:
|
||||
if not subscription:
|
||||
logger.warning(f"Подписки для пользователя {telegram_id} не найдены")
|
||||
raise HTTPException(status_code=404, detail="No subscriptions found")
|
||||
|
||||
plan = await database_manager.get_plan_by_id(subscription.plan_id)
|
||||
if not plan:
|
||||
logger.warning(f"Тариф для подписки {subscription.id} не найден")
|
||||
plan_name = "Unknown"
|
||||
else:
|
||||
plan_name = plan.name
|
||||
# Формируем список подписок для ответа
|
||||
return [
|
||||
{
|
||||
"id": sub.id,
|
||||
"plan": sub.plan,
|
||||
"vpn_server_id": sub.vpn_server_id,
|
||||
"expiry_date": sub.expiry_date.isoformat(),
|
||||
"created_at": sub.created_at.isoformat(),
|
||||
"updated_at": sub.updated_at.isoformat(),
|
||||
}
|
||||
for sub in subscriptions
|
||||
]
|
||||
except HTTPException as e:
|
||||
raise e
|
||||
# return [
|
||||
# {
|
||||
# "id": sub.id,
|
||||
# "plan": sub.plan,
|
||||
# "vpn_server_id": sub.vpn_server_id,
|
||||
# "expiry_date": sub.expiry_date.isoformat(),
|
||||
# "created_at": sub.created_at.isoformat(),
|
||||
# "updated_at": sub.updated_at.isoformat(),
|
||||
# }
|
||||
# for sub in subscription
|
||||
# ]
|
||||
return [{
|
||||
"id": str(subscription.id), # Конвертируем UUID в строку
|
||||
"user_id": subscription.user_id,
|
||||
"plan_name": plan_name,
|
||||
"vpn_server_id": subscription.vpn_server_id,
|
||||
"end_date": subscription.end_date.isoformat(),
|
||||
"status": subscription.status.value, # Извлекаем значение enum
|
||||
"start_date": subscription.start_date.isoformat(),
|
||||
"created_at": subscription.created_at.isoformat()
|
||||
}]
|
||||
except SQLAlchemyError as e:
|
||||
logger.error(f"Ошибка базы данных при получении подписок для пользователя {telegram_id}: {e}")
|
||||
raise HTTPException(status_code=500, detail="Database error")
|
||||
|
||||
Reference in New Issue
Block a user