Skip to content

Commit

Permalink
Merge pull request #13 from nickatnight/fix-missing-versions-folder
Browse files Browse the repository at this point in the history
Add .gitkeep to versions folder
  • Loading branch information
nickatnight authored Feb 7, 2023
2 parents d84b44d + 8f7a58e commit 7682a62
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class {{ cookiecutter.project_name|title|replace(' ', '') }}Exception(Exception):
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from src.db.session import SessionLocal
from src.models.meme import Meme


logging.basicConfig(level=logging.INFO)


Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 7682a62

Please sign in to comment.