Add list_marketplaces to MarketService protocol, impl, and stub
Paginated query for market listings — supports optional container filtering and returns (dtos, has_more) for infinite scroll. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -155,6 +155,12 @@ class MarketService(Protocol):
|
|||||||
name: str, slug: str,
|
name: str, slug: str,
|
||||||
) -> MarketPlaceDTO: ...
|
) -> MarketPlaceDTO: ...
|
||||||
|
|
||||||
|
async def list_marketplaces(
|
||||||
|
self, session: AsyncSession,
|
||||||
|
container_type: str | None = None, container_id: int | None = None,
|
||||||
|
*, page: int = 1, per_page: int = 20,
|
||||||
|
) -> tuple[list[MarketPlaceDTO], bool]: ...
|
||||||
|
|
||||||
async def soft_delete_marketplace(
|
async def soft_delete_marketplace(
|
||||||
self, session: AsyncSession, container_type: str, container_id: int,
|
self, session: AsyncSession, container_type: str, container_id: int,
|
||||||
slug: str,
|
slug: str,
|
||||||
|
|||||||
@@ -52,6 +52,23 @@ class SqlMarketService:
|
|||||||
)
|
)
|
||||||
return [_mp_to_dto(mp) for mp in result.scalars().all()]
|
return [_mp_to_dto(mp) for mp in result.scalars().all()]
|
||||||
|
|
||||||
|
async def list_marketplaces(
|
||||||
|
self, session: AsyncSession,
|
||||||
|
container_type: str | None = None, container_id: int | None = None,
|
||||||
|
*, page: int = 1, per_page: int = 20,
|
||||||
|
) -> tuple[list[MarketPlaceDTO], bool]:
|
||||||
|
stmt = select(MarketPlace).where(MarketPlace.deleted_at.is_(None))
|
||||||
|
if container_type is not None and container_id is not None:
|
||||||
|
stmt = stmt.where(
|
||||||
|
MarketPlace.container_type == container_type,
|
||||||
|
MarketPlace.container_id == container_id,
|
||||||
|
)
|
||||||
|
stmt = stmt.order_by(MarketPlace.name.asc())
|
||||||
|
stmt = stmt.offset((page - 1) * per_page).limit(per_page + 1)
|
||||||
|
rows = (await session.execute(stmt)).scalars().all()
|
||||||
|
has_more = len(rows) > per_page
|
||||||
|
return [_mp_to_dto(mp) for mp in rows[:per_page]], has_more
|
||||||
|
|
||||||
async def product_by_id(self, session: AsyncSession, product_id: int) -> ProductDTO | None:
|
async def product_by_id(self, session: AsyncSession, product_id: int) -> ProductDTO | None:
|
||||||
product = (
|
product = (
|
||||||
await session.execute(select(Product).where(Product.id == product_id))
|
await session.execute(select(Product).where(Product.id == product_id))
|
||||||
|
|||||||
@@ -156,6 +156,13 @@ class StubMarketService:
|
|||||||
) -> list[MarketPlaceDTO]:
|
) -> list[MarketPlaceDTO]:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
async def list_marketplaces(
|
||||||
|
self, session: AsyncSession,
|
||||||
|
container_type: str | None = None, container_id: int | None = None,
|
||||||
|
*, page: int = 1, per_page: int = 20,
|
||||||
|
) -> tuple[list[MarketPlaceDTO], bool]:
|
||||||
|
return [], False
|
||||||
|
|
||||||
async def product_by_id(self, session: AsyncSession, product_id: int) -> ProductDTO | None:
|
async def product_by_id(self, session: AsyncSession, product_id: int) -> ProductDTO | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user