-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created admin table #23
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import List | ||
|
||
from fastapi import Depends | ||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from identity_socializer.db.dependencies import get_db_session | ||
from identity_socializer.db.models.admin_model import AdminModel | ||
|
||
|
||
class AdminDAO: | ||
"""Class for accessing admins table.""" | ||
|
||
def __init__(self, session: AsyncSession = Depends(get_db_session)): | ||
self.session = session | ||
|
||
async def create_admin_model( | ||
self, | ||
admin_id: str, | ||
email: str, | ||
) -> None: | ||
"""Add single admin to session.""" | ||
admin_model = AdminModel( | ||
id=admin_id, | ||
email=email, | ||
) | ||
|
||
self.session.add(admin_model) | ||
|
||
async def get_all_admins(self, limit: int, offset: int) -> List[AdminModel]: | ||
""" | ||
Get all admins models with limit/offset pagination. | ||
|
||
:param limit: limit of admins. | ||
:param offset: offset of admins. | ||
:return: stream of admins. | ||
""" | ||
raw_admins = await self.session.execute( | ||
select(AdminModel).limit(limit).offset(offset), | ||
) | ||
|
||
return list(raw_admins.scalars().fetchall()) |
31 changes: 31 additions & 0 deletions
31
identity_socializer/db/migrations/versions/2023-10-19-14-45_22ac5d68869b.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""create admin table | ||
|
||
Revision ID: 22ac5d68869b | ||
Revises: 847eee4ea866 | ||
Create Date: 2023-10-19 14:45:52.775871 | ||
|
||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "22ac5d68869b" | ||
down_revision = "847eee4ea866" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
length = 200 | ||
|
||
op.create_table( | ||
"admins", | ||
sa.Column("id", sa.String(length), nullable=False), | ||
sa.Column("email", sa.String(length), nullable=False), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("admins") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import datetime | ||
|
||
from sqlalchemy.orm import Mapped, mapped_column | ||
from sqlalchemy.sql.sqltypes import DateTime, String | ||
|
||
from identity_socializer.db.base import Base | ||
|
||
|
||
class AdminModel(Base): | ||
"""Model for Admin.""" | ||
|
||
__tablename__ = "admins" | ||
|
||
length = 200 | ||
|
||
id: Mapped[str] = mapped_column(primary_key=True) | ||
email: Mapped[str] = mapped_column(String(length)) | ||
created_at: Mapped[DateTime] = mapped_column( | ||
DateTime, | ||
default=datetime.datetime.utcnow, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renombrar a admin dao?