-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ijaric/fix/#6_fix_template
Исправление мелких багов в "Шаблоне" #6
- Loading branch information
Showing
78 changed files
with
220 additions
and
2,622 deletions.
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
POSTGRES_PROTOCOL=postgresql+asyncpg | ||
POSTGRES_DRIVER=postgresql+asyncpg | ||
POSTGRES_HOST=db | ||
POSTGRES_PORT=5432 | ||
POSTGRES_USER=user | ||
POSTGRES_PASSWORD=Qwe123 | ||
POSTGRES_NAME=api_db | ||
POSTGRES_DB_NAME=api_db | ||
|
||
NGINX_PORT=80 | ||
API_HOST=0.0.0.0 | ||
API_PORT=8000 | ||
|
||
JWT_SECRET_KEY=v9LctjUWwol4XbvczPiLFMDtZ8aal7mm | ||
JWT_ALGORITHM=HS256 | ||
|
||
APP_RELOAD=True |
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 |
---|---|---|
@@ -1 +1 @@ | ||
Generic single-database configuration with an async dbapi. | ||
Generic single-database configuration with an async dbapi. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .health import * | ||
|
||
__all__ = [ | ||
"health_router", | ||
"basic_router", | ||
] |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .liveness_probe import router as health_router | ||
from .liveness_probe import basic_router | ||
|
||
__all__ = [ | ||
"health_router", | ||
"basic_router", | ||
] |
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
Empty file.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from .base import * | ||
from .base import HealthResponseModel | ||
|
||
__all__ = [ | ||
"HealthResponseModel", | ||
"TokenResponseModel", | ||
] |
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
import uuid | ||
|
||
import pydantic | ||
|
||
|
||
class TokenResponseModel(pydantic.BaseModel): | ||
sub: uuid.UUID | ||
exp: int | None = None | ||
|
||
|
||
class HealthResponseModel(pydantic.BaseModel): | ||
status: str = pydantic.Field(default=..., examples=["healthy"], description="Схема доступности сервиса") |
Empty file.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
|
||
__all__ = [ | ||
"Application", | ||
"Settings", | ||
"ApplicationError", | ||
"DisposeError", | ||
"Settings", | ||
"StartServerError", | ||
] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .postgres import get_async_session | ||
from .httpx import get_async_http_session | ||
from .postgres import AsyncPostgresClient | ||
|
||
__all__ = ["get_async_session"] | ||
__all__ = ["AsyncPostgresClient", "get_async_http_session"] |
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,16 @@ | ||
import contextlib | ||
import typing | ||
|
||
import httpx | ||
|
||
|
||
@contextlib.asynccontextmanager | ||
async def get_async_http_session( | ||
settings: dict[str, typing.Any] | None = None | ||
) -> typing.AsyncGenerator[httpx.AsyncClient, None]: | ||
"""Async http client.""" | ||
if settings is None: | ||
settings = {} | ||
client = httpx.AsyncClient(**settings) # Insert your own settings here | ||
async with client as ac: | ||
yield ac |
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 |
---|---|---|
@@ -1,24 +1,30 @@ | ||
import sqlalchemy.ext.asyncio as sa_asyncio | ||
|
||
import lib.app.split_settings as app_split_settings | ||
import lib.app.settings as app_settings | ||
|
||
|
||
async def get_async_session( | ||
settings: app_split_settings.DBSettings, | ||
) -> sa_asyncio.async_sessionmaker[sa_asyncio.AsyncSession]: | ||
engine = sa_asyncio.create_async_engine( | ||
url=settings.dsn, | ||
pool_size=settings.pool_size, | ||
pool_pre_ping=settings.pool_pre_ping, | ||
echo=settings.echo, | ||
future=True, | ||
) | ||
class AsyncPostgresClient: | ||
"""Async Postgres Client that return sessionmaker.""" | ||
|
||
async_session = sa_asyncio.async_sessionmaker( | ||
bind=engine, | ||
autocommit=settings.auto_commit, | ||
autoflush=settings.auto_flush, | ||
expire_on_commit=settings.expire_on_commit, | ||
) | ||
def __init__(self, settings: app_settings.Settings) -> None: | ||
self.settings = settings.postgres | ||
self.async_enging = sa_asyncio.create_async_engine( | ||
url=self.settings.dsn, | ||
pool_size=self.settings.pool_size, | ||
pool_pre_ping=self.settings.pool_pre_ping, | ||
echo=self.settings.echo, | ||
future=True, | ||
) | ||
|
||
return async_session # noqa: RET504 | ||
def get_async_session(self) -> sa_asyncio.async_sessionmaker[sa_asyncio.AsyncSession]: | ||
async_session = sa_asyncio.async_sessionmaker( | ||
bind=self.async_enging, | ||
autocommit=self.settings.auto_commit, | ||
autoflush=self.settings.auto_flush, | ||
expire_on_commit=self.settings.expire_on_commit, | ||
) | ||
|
||
return async_session # noqa: RET504 | ||
|
||
async def dispose_callback(self) -> None: | ||
await self.async_enging.dispose() |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .base_sqlalchemy import Base | ||
from .base_sqlalchemy import Base, IdCreatedUpdatedBaseMixin | ||
from .token import Token | ||
|
||
__all__ = ["Base"] | ||
__all__ = ["Base", "IdCreatedUpdatedBaseMixin", "Token"] |
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 |
---|---|---|
@@ -1,5 +1,36 @@ | ||
import uuid | ||
|
||
import sqlalchemy | ||
import sqlalchemy.dialects.postgresql | ||
import sqlalchemy.ext.declarative | ||
import sqlalchemy.orm | ||
|
||
|
||
class Base(sqlalchemy.orm.DeclarativeBase): | ||
"""Base class for all models.""" | ||
|
||
pass | ||
|
||
|
||
class IdCreatedUpdatedBaseMixin(Base): | ||
@sqlalchemy.ext.declarative.declared_attr | ||
def uuid(cls): | ||
return sqlalchemy.Column( | ||
sqlalchemy.dialects.postgresql.UUID(as_uuid=True), | ||
primary_key=True, | ||
default=uuid.uuid4, | ||
unique=True, | ||
nullable=False, | ||
) | ||
|
||
@sqlalchemy.ext.declarative.declared_attr | ||
def created_at(cls): | ||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now()) | ||
|
||
@sqlalchemy.ext.declarative.declared_attr | ||
def updated_at(cls): | ||
return sqlalchemy.Column(sqlalchemy.DateTime, server_default=sqlalchemy.sql.func.now()) | ||
|
||
@sqlalchemy.ext.declarative.declared_attr.directive | ||
def __tablename__(cls) -> str: | ||
return cls.__name__.lower() |
Oops, something went wrong.