diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/api/v1/meme.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/api/v1/meme.py index d7222a4..7d2c1df 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/api/v1/meme.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/api/v1/meme.py @@ -1,12 +1,12 @@ -from typing import Optional, List +from typing import List, Optional from fastapi import APIRouter, Depends, Query from sqlalchemy.ext.asyncio import AsyncSession from src.core.enums import SortOrder from src.db.session import get_session -from src.repositories.sqlalchemy import SQLAlchemyRepository from src.models.meme import Meme +from src.repositories.sqlalchemy import SQLAlchemyRepository from src.schemas.common import IGetResponseBase from src.schemas.meme import IMemeRead @@ -28,6 +28,8 @@ async def memes( session: AsyncSession = Depends(get_session), ) -> IGetResponseBase[List[IMemeRead]]: meme_repo = SQLAlchemyRepository(model=Meme, db=session) - memes = await meme_repo.all(skip=skip, limit=limit, sort_field=sort_field, sort_order=sort_order) + memes = await meme_repo.all( + skip=skip, limit=limit, sort_field=sort_field, sort_order=sort_order + ) return IGetResponseBase[List[IMemeRead]](data=memes) diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/core/exceptions.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/core/exceptions.py index a8c5ca5..8c3a083 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/core/exceptions.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/core/exceptions.py @@ -1,4 +1,3 @@ - class {{ cookiecutter.project_name|title|replace(' ', '') }}Exception(Exception): pass diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/db/init_db.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/db/init_db.py index 8557f2f..759088d 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/db/init_db.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/db/init_db.py @@ -4,6 +4,7 @@ from src.db.session import SessionLocal from src.models.meme import Meme + logging.basicConfig(level=logging.INFO) diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/interfaces/repository.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/interfaces/repository.py index 9180070..7a78bf0 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/interfaces/repository.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/interfaces/repository.py @@ -1,5 +1,5 @@ from abc import ABCMeta, abstractmethod -from typing import Generic, Optional, TypeVar, List +from typing import Generic, List, Optional, TypeVar T = TypeVar("T") @@ -29,6 +29,12 @@ async def delete(self, **kwargs: int) -> None: raise NotImplementedError @abstractmethod - async def all(self, skip: int = 0, limit: int = 50, sort_field: Optional[str] = None, sort_order: Optional[str] = None) -> List[T]: + async def all( + self, + skip: int = 0, + limit: int = 50, + sort_field: Optional[str] = None, + sort_order: Optional[str] = None + ) -> List[T]: """Delete one instance by filter.""" raise NotImplementedError diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/migrations/versions/.gitkeep b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/migrations/versions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/repositories/sqlalchemy.py b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/repositories/sqlalchemy.py index a5746c9..f8b3d6a 100644 --- a/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/repositories/sqlalchemy.py +++ b/{{ cookiecutter.project_slug }}/{{ cookiecutter.backend_container_name }}/src/repositories/sqlalchemy.py @@ -7,12 +7,12 @@ from src.core.exceptions import ObjectNotFound from src.interfaces.repository import IRepository + ModelType = TypeVar("ModelType", bound=SQLModel) logger: logging.Logger = logging.getLogger(__name__) class SQLAlchemyRepository(IRepository[ModelType]): - def __init__(self, model: Type[ModelType], db: AsyncSession) -> None: self.model = model self.db = db @@ -92,12 +92,7 @@ async def all( sort_order = "desc" order_by = getattr(columns[sort_field], sort_order)() - query = ( - select(self.model) - .offset(skip) - .limit(limit) - .order_by(order_by) - ) + query = select(self.model).offset(skip).limit(limit).order_by(order_by) response = await self.db.execute(query) return response.scalars().all()