コード例 #1
0
    async def get_user_by_username(self, *, username: str) -> UserInDB:
        user_row = await self.collection.find_one({"username": username})

        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(format_strings.USER_DOES_NOT_EXIST_WITH_USERNAME.format(username))
コード例 #2
0
    async def get_user_by_email(self, *, email: str) -> UserInDB:
        user_row = await self.collection.find_one({"email": email})

        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(format_strings.USER_DOES_NOT_EXIST_WITH_EMAIL.format(email))
コード例 #3
0
    async def get_user_by_username(self, *, username: str) -> UserInDB:
        user_row = await self._log_and_fetch_row(FIND_BY_USERNAME, username)
        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(
            "user with username {0} does not exist".format(username))
コード例 #4
0
    async def get_user_by_email(self, *, email: str) -> UserInDB:
        user_row = await self._log_and_fetch_row(FIND_BY_EMAIL, email)
        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(
            "user with email {0} does not exist".format(email))
コード例 #5
0
ファイル: users.py プロジェクト: HolyShining/little-friends
    async def get_user_by_email(self, *, email: str) -> UserInDB:
        user_row = await queries.get_user_by_email(self.connection,
                                                   email=email)
        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(
            "user with email {0} does not exist".format(email))
コード例 #6
0
ファイル: users.py プロジェクト: HolyShining/little-friends
    async def get_user_by_name(self, *, name: str) -> UserInDB:
        user_row = await queries.get_user_by_name(
            self.connection,
            name=name,
        )
        if user_row:
            return UserInDB(**user_row)

        raise EntityDoesNotExist(
            "user with name {0} does not exist".format(name), )
コード例 #7
0
    async def get_client_by_client_id(self, *, client_id: str) -> ClientInDB:
        client_row = await queries.get_client_by_client_id(
            self.connection,
            client_id=client_id,
        )
        if client_row:
            return ClientInDB(**client_row)

        raise EntityDoesNotExist(
            "client with client_id {0} does not exist".format(client_id), )
コード例 #8
0
ファイル: users.py プロジェクト: dt50/Fastapi-Notebook
    async def get_user_id(self, *, login: str, password: str) -> UserOut:
        user_row = await queries.get_user_id(
            self.connection,
            login=login,
            password=password
        )
        if user_row:
            return UserOut(**dict(user_row))

        raise EntityDoesNotExist(
            "user with username {0} does not exist".format(login),
        )
コード例 #9
0
    async def get_article_by_slug(
        self, *, slug: str, requested_user: Optional[User] = None
    ) -> Article:
        article_row = await self._log_and_fetch_row(GET_ARTICLE_BY_SLUG_QUERY, slug)
        if article_row:
            return await self._get_article_from_db_record(
                article_row=article_row,
                slug=article_row["slug"],
                author_username=article_row[AUTHOR_USERNAME_ALIAS],
                requested_user=requested_user,
            )

        raise EntityDoesNotExist("article with slug {0} does not exist".format(slug))
コード例 #10
0
    async def get_note_by_id(self, login: str, password: str,
                             id: int) -> NoteIn:
        note_row = await queries.get_user_note(self.connection,
                                               login=login,
                                               password=password,
                                               id=id)

        if note_row:
            return NoteIn(**note_row)

        raise EntityDoesNotExist(
            "note with id={0} for user with login={1} does not exist".format(
                id, login), )
コード例 #11
0
    async def get_comment_by_id(self,
                                *,
                                comment_id: int,
                                article: Article,
                                user: Optional[User] = None) -> Comment:
        comment_row = await self._log_and_fetch_row(
            GET_COMMENT_FOR_ARTICLE_BY_ID, comment_id, article.slug)
        if comment_row:
            return await self._get_comment_from_db_record(
                comment_row=comment_row,
                author_username=comment_row["author_username"],
                requested_user=user,
            )

        raise EntityDoesNotExist(
            "comment with id {0} does not exist".format(comment_id))
コード例 #12
0
    async def get_article_by_slug(
        self,
        *,
        slug: str,
        requested_user: Optional[User] = None,
    ) -> Article:
        article_row = await queries.get_article_by_slug(self.connection,
                                                        slug=slug)
        if article_row:
            return await self._get_article_from_db_record(
                article_row=article_row,
                slug=article_row[SLUG_ALIAS],
                author_username=article_row[AUTHOR_USERNAME_ALIAS],
                requested_user=requested_user,
            )

        raise EntityDoesNotExist(
            "article with slug {0} does not exist".format(slug))
コード例 #13
0
    async def get_comment_by_id(
        self,
        *,
        comment_id: int,
        article: Article,
        user: Optional[User] = None,
    ) -> Comment:
        comment_row = await queries.get_comment_by_id_and_slug(
            self.connection,
            comment_id=comment_id,
            article_slug=article.slug,
        )
        if comment_row:
            return await self._get_comment_from_db_record(
                comment_row=comment_row,
                author_username=comment_row["author_username"],
                requested_user=user,
            )

        raise EntityDoesNotExist(
            "comment with id {0} does not exist".format(comment_id), )