Files
new_lottery_bot/src/interfaces/base.py
Andrew K. Choi 43d46ea6f8 refactor: clean up unused code and duplicate handlers
- Removed duplicate admin callback handlers from main.py (moved to admin_panel.py)
- Removed unused methods from BotController (handle_admin_panel, handle_lottery_management, handle_conduct_lottery_admin, handle_conduct_lottery)
- Removed unused keyboard methods from ui.py (get_lottery_management_keyboard, get_lottery_keyboard, get_conduct_lottery_keyboard)
- Simplified IBotController interface to only essential methods
- Simplified IKeyboardBuilder interface to only used methods
- Fixed cmd_admin handler to directly show admin panel
- Bot now uses centralized admin handlers from admin_panel.py
2025-11-17 08:00:39 +09:00

164 lines
5.1 KiB
Python
Raw 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 abc import ABC, abstractmethod
from typing import Optional, List, Dict, Any
from src.core.models import User, Lottery, Participation, Winner
class IUserRepository(ABC):
"""Интерфейс репозитория пользователей"""
@abstractmethod
async def get_by_telegram_id(self, telegram_id: int) -> Optional[User]:
"""Получить пользователя по Telegram ID"""
pass
@abstractmethod
async def create(self, **kwargs) -> User:
"""Создать нового пользователя"""
pass
@abstractmethod
async def update(self, user: User) -> User:
"""Обновить пользователя"""
pass
@abstractmethod
async def get_all(self) -> List[User]:
"""Получить всех пользователей"""
pass
class ILotteryRepository(ABC):
"""Интерфейс репозитория розыгрышей"""
@abstractmethod
async def get_by_id(self, lottery_id: int) -> Optional[Lottery]:
"""Получить розыгрыш по ID"""
pass
@abstractmethod
async def create(self, **kwargs) -> Lottery:
"""Создать новый розыгрыш"""
pass
@abstractmethod
async def get_active(self) -> List[Lottery]:
"""Получить активные розыгрыши"""
pass
@abstractmethod
async def get_all(self) -> List[Lottery]:
"""Получить все розыгрыши"""
pass
@abstractmethod
async def update(self, lottery: Lottery) -> Lottery:
"""Обновить розыгрыш"""
pass
class IParticipationRepository(ABC):
"""Интерфейс репозитория участий"""
@abstractmethod
async def create(self, **kwargs) -> Participation:
"""Создать новое участие"""
pass
@abstractmethod
async def get_by_lottery(self, lottery_id: int) -> List[Participation]:
"""Получить участия по розыгрышу"""
pass
@abstractmethod
async def get_count_by_lottery(self, lottery_id: int) -> int:
"""Получить количество участников в розыгрыше"""
pass
class IWinnerRepository(ABC):
"""Интерфейс репозитория победителей"""
@abstractmethod
async def create(self, **kwargs) -> Winner:
"""Создать запись о победителе"""
pass
@abstractmethod
async def get_by_lottery(self, lottery_id: int) -> List[Winner]:
"""Получить победителей розыгрыша"""
pass
class ILotteryService(ABC):
"""Интерфейс сервиса розыгрышей"""
@abstractmethod
async def create_lottery(self, title: str, description: str, prizes: List[str], creator_id: int) -> Lottery:
"""Создать новый розыгрыш"""
pass
@abstractmethod
async def conduct_draw(self, lottery_id: int) -> Dict[str, Any]:
"""Провести розыгрыш"""
pass
@abstractmethod
async def get_active_lotteries(self) -> List[Lottery]:
"""Получить активные розыгрыши"""
pass
class IUserService(ABC):
"""Интерфейс сервиса пользователей"""
@abstractmethod
async def get_or_create_user(self, telegram_id: int, **kwargs) -> User:
"""Получить или создать пользователя"""
pass
@abstractmethod
async def register_user(self, telegram_id: int, phone: str, club_card_number: str) -> bool:
"""Зарегистрировать пользователя"""
pass
class IBotController(ABC):
"""Интерфейс контроллера бота"""
@abstractmethod
async def handle_start(self, message_or_callback):
"""Обработать команду /start"""
pass
@abstractmethod
async def handle_active_lotteries(self, callback):
"""Обработать показ активных розыгрышей"""
pass
class IMessageFormatter(ABC):
"""Интерфейс форматирования сообщений"""
@abstractmethod
def format_lottery_info(self, lottery: Lottery, participants_count: int) -> str:
"""Форматировать информацию о розыгрыше"""
pass
@abstractmethod
def format_winners_list(self, winners: List[Winner]) -> str:
"""Форматировать список победителей"""
pass
class IKeyboardBuilder(ABC):
"""Интерфейс создания клавиатур"""
@abstractmethod
def get_main_keyboard(self, is_admin: bool, is_registered: bool = False):
"""Получить главную клавиатуру"""
pass
@abstractmethod
def get_admin_keyboard(self):
"""Получить админскую клавиатуру"""
pass