MVP ready. Fully functional (registration? moderation, profiles vew)
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
24
services/bot/app/repositories/admin_repo.py
Normal file
24
services/bot/app/repositories/admin_repo.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.admin import Admin
|
||||
|
||||
class AdminRepository:
|
||||
"""Работа с таблицей администраторов."""
|
||||
|
||||
def __init__(self, session: Session):
|
||||
self.s = session
|
||||
|
||||
def is_admin(self, telegram_id: int) -> bool:
|
||||
"""Проверка, является ли пользователь администратором."""
|
||||
return self.s.query(Admin).filter(Admin.telegram_id == telegram_id).first() is not None
|
||||
|
||||
def add_admin(self, telegram_id: int, full_name: str | None = None) -> Admin:
|
||||
"""Добавить нового администратора."""
|
||||
admin = Admin(telegram_id=telegram_id, full_name=full_name)
|
||||
self.s.add(admin)
|
||||
self.s.commit()
|
||||
return admin
|
||||
|
||||
def get_all_admins(self) -> list[Admin]:
|
||||
"""Получить всех администраторов."""
|
||||
return self.s.query(Admin).all()
|
||||
40
services/bot/app/repositories/candidate_repo.py
Normal file
40
services/bot/app/repositories/candidate_repo.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.candidate import Candidate
|
||||
|
||||
|
||||
class CandidateRepository:
|
||||
"""Работа с таблицей кандидатов."""
|
||||
|
||||
def __init__(self, session: Session):
|
||||
self.s = session
|
||||
|
||||
def by_tg(self, telegram_id: int) -> Candidate | None:
|
||||
"""Найти анкету по Telegram ID."""
|
||||
return self.s.query(Candidate).filter(Candidate.telegram_id == telegram_id).first()
|
||||
|
||||
def by_id(self, candidate_id: int) -> Candidate | None:
|
||||
"""Найти анкету по ID."""
|
||||
return self.s.get(Candidate, candidate_id)
|
||||
|
||||
def all(self, limit: int = 100) -> list[Candidate]:
|
||||
"""Получить список всех анкет (с лимитом)."""
|
||||
return self.s.query(Candidate).order_by(Candidate.created_at.desc()).limit(limit).all()
|
||||
|
||||
def add(self, candidate: Candidate) -> Candidate:
|
||||
"""Добавить новую анкету."""
|
||||
self.s.add(candidate)
|
||||
self.s.commit()
|
||||
self.s.refresh(candidate)
|
||||
return candidate
|
||||
|
||||
def update(self, candidate: Candidate) -> Candidate:
|
||||
"""Обновить существующую анкету."""
|
||||
self.s.commit()
|
||||
self.s.refresh(candidate)
|
||||
return candidate
|
||||
|
||||
def delete(self, candidate: Candidate) -> None:
|
||||
"""Удалить анкету."""
|
||||
self.s.delete(candidate)
|
||||
self.s.commit()
|
||||
Reference in New Issue
Block a user