Refactor promo code handling in admin panel and clean up unused methods

- Replaced the promo_codes module with a new promo management structure, enhancing organization and clarity in the admin panel.
- Updated admin panel handlers to utilize the new promo management methods, improving the flow of promo code creation and management.
- Removed deprecated methods from payment and subscription data access layers, streamlining the codebase and improving maintainability.
- Ensured localization files are updated to reflect changes in promo management messaging, enhancing user experience.
This commit is contained in:
machka-pasla
2025-08-05 14:55:55 +03:00
parent c5f41a261b
commit 9cf5a93625
10 changed files with 1388 additions and 1790 deletions
-58
View File
@@ -81,18 +81,6 @@ async def update_user_language(
return result.rowcount > 0
async def set_user_ban_status(
session: AsyncSession, user_id: int, is_banned: bool
) -> bool:
user = await get_user_by_id(session, user_id)
if user:
user.is_banned = is_banned
await session.flush()
await session.refresh(user)
return True
return False
async def get_banned_users(session: AsyncSession) -> List[User]:
"""Get all banned users"""
stmt = (
@@ -104,58 +92,12 @@ async def get_banned_users(session: AsyncSession) -> List[User]:
return result.scalars().all()
async def get_banned_users_paginated(
session: AsyncSession, limit: int, offset: int
) -> Tuple[List[User], int]:
stmt_users = (
select(User)
.where(User.is_banned == True)
.order_by(User.registration_date.desc())
.limit(limit)
.offset(offset)
)
result_users = await session.execute(stmt_users)
users_list = result_users.scalars().all()
stmt_count = select(func.count()).select_from(User).where(User.is_banned == True)
result_count = await session.execute(stmt_count)
total_banned = result_count.scalar_one()
return users_list, total_banned
async def get_all_active_user_ids_for_broadcast(session: AsyncSession) -> List[int]:
stmt = select(User.user_id).where(User.is_banned == False)
result = await session.execute(stmt)
return result.scalars().all()
async def get_user_count_stats_dal(session: AsyncSession) -> Dict[str, int]:
total_users_stmt = select(func.count(User.user_id)).select_from(User)
banned_users_stmt = (
select(func.count(User.user_id)).select_from(User).where(User.is_banned == True)
)
active_subs_stmt = (
select(func.count(func.distinct(Subscription.user_id)))
.join(User, Subscription.user_id == User.user_id)
.where(Subscription.is_active == True)
.where(Subscription.end_date > datetime.now())
)
total_users = (await session.execute(total_users_stmt)).scalar_one_or_none() or 0
banned_users = (await session.execute(banned_users_stmt)).scalar_one_or_none() or 0
active_subs_users = (
await session.execute(active_subs_stmt)
).scalar_one_or_none() or 0
return {
"total_users": total_users,
"banned_users": banned_users,
"users_with_active_subscriptions": active_subs_users,
}
async def get_all_users_with_panel_uuid(session: AsyncSession) -> List[User]:
stmt = select(User).where(User.panel_user_uuid.is_not(None))
result = await session.execute(stmt)