From 1e59bab7e1bea29418e26086bd8a119b5f81a37e Mon Sep 17 00:00:00 2001 From: Evgenii Goncharov Date: Tue, 12 Sep 2023 20:11:12 -0700 Subject: [PATCH] task1_attempt1 --- .gitignore | 2 ++ src/core/db/repository/administrator_invitation.py | 11 +++++++++-- src/core/services/administrator_invitation.py | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index cc774935a..a5fdeb43f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ fill_db.log # Frontend build frontend/ + +venv/ diff --git a/src/core/db/repository/administrator_invitation.py b/src/core/db/repository/administrator_invitation.py index 0d050fe99..4e2e57d99 100644 --- a/src/core/db/repository/administrator_invitation.py +++ b/src/core/db/repository/administrator_invitation.py @@ -3,12 +3,12 @@ from uuid import UUID from fastapi import Depends -from sqlalchemy import and_, select +from sqlalchemy import and_, not_, select from sqlalchemy.ext.asyncio import AsyncSession from src.core import exceptions from src.core.db.db import get_session -from src.core.db.models import AdministratorInvitation +from src.core.db.models import Administrator, AdministratorInvitation from src.core.db.repository import AbstractRepository @@ -27,3 +27,10 @@ async def get_mail_request_by_token(self, token: UUID) -> Optional[Administrator if result is None: raise exceptions.AdministratorInvitationInvalidError return result + + async def get_all_invitations(self): + """Возвращает из БД список приглашений, email которых не состоят в списке администраторов.""" + statement = select(AdministratorInvitation).where( + not_(AdministratorInvitation.email.in_(select(Administrator.email))) + ) + return (await self._session.scalars(statement)).all() diff --git a/src/core/services/administrator_invitation.py b/src/core/services/administrator_invitation.py index c6bb0e854..fdb6e56f5 100644 --- a/src/core/services/administrator_invitation.py +++ b/src/core/services/administrator_invitation.py @@ -47,7 +47,7 @@ async def close_invitation(self, token: UUID) -> None: await self.__administrator_mail_request_repository.update(invitation.id, invitation) async def list_all_invitations(self) -> list[AdministratorInvitation]: - return await self.__administrator_mail_request_repository.get_all() + return await self.__administrator_mail_request_repository.get_all_invitations() async def get_invitation_by_id(self, invitation_id: UUID) -> AdministratorInvitation: return await self.__administrator_mail_request_repository.get(invitation_id)