diff --git a/u232ping/controller.py b/u232ping/controller.py new file mode 100644 index 0000000..9e454e9 --- /dev/null +++ b/u232ping/controller.py @@ -0,0 +1,27 @@ +from u232ping.abc.db import DataBase +from u232ping.types import Group +from aiogram.types import Message + +class Controller(object): + + db: DataBase + + def __init__(self, db_implementation: DataBase) -> None: + self.db = db_implementation + + async def _ping(self, msg: Message, group: int | None = None) -> None: + gtp: Group + if group is None: + gtp = await self.db.get_all() + else: + gtp = await self.db.get_group(group) + msg.answer(str(gtp)) + + async def all(self, msg: Message) -> None: + await self._ping(msg) + + async def first(self, msg: Message) -> None: + await self._ping(msg, 1) + + async def second(self, msg: Message) -> None: + await self._ping(msg, 2)