[preset] GO
This commit is contained in:
parent
bec52975ae
commit
9a84abc0ad
2 changed files with 10 additions and 3 deletions
|
@ -12,7 +12,7 @@ class ListPresets(AuthorizedController):
|
||||||
) -> AsyncIterator[Preset]:
|
) -> AsyncIterator[Preset]:
|
||||||
async with self.async_session() as session:
|
async with self.async_session() as session:
|
||||||
async for preset in DBPreset.list_all(
|
async for preset in DBPreset.list_all(
|
||||||
session, limit=limit, offset=offset, q=q
|
session, user_id=self.user.id, limit=limit, offset=offset, q=q
|
||||||
):
|
):
|
||||||
yield Preset.from_orm(preset)
|
yield Preset.from_orm(preset)
|
||||||
|
|
||||||
|
|
|
@ -80,12 +80,19 @@ class Preset(Base, CommonMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def list_all(
|
async def list_all(
|
||||||
cls, session: AsyncSession, offset: int, limit: int, q: Optional[str] = None
|
cls,
|
||||||
|
session: AsyncSession,
|
||||||
|
user_id: int,
|
||||||
|
offset: int,
|
||||||
|
limit: int,
|
||||||
|
q: Optional[str] = None,
|
||||||
) -> AsyncIterator["Preset"]:
|
) -> AsyncIterator["Preset"]:
|
||||||
query = select(cls)
|
query = select(cls)
|
||||||
|
|
||||||
if q:
|
if q:
|
||||||
query = query.filter(cls.name.ilike(f"%{q.lower()}%"))
|
query = query.filter(cls.user_id == user_id).filter(
|
||||||
|
cls.name.ilike(f"%{q.lower()}%")
|
||||||
|
)
|
||||||
|
|
||||||
query = query.offset(offset).limit(limit)
|
query = query.offset(offset).limit(limit)
|
||||||
stream = await session.stream_scalars(query.order_by(cls.id))
|
stream = await session.stream_scalars(query.order_by(cls.id))
|
||||||
|
|
Loading…
Reference in a new issue