Skip to content

Commit

Permalink
server/product: add id filter to list endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Jan 6, 2025
1 parent 237735d commit ffcd491
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/polar/product/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ async def list(
pagination: PaginationParamsQuery,
sorting: ListSorting,
auth_subject: auth.CreatorProductsRead,
id: MultipleQueryFilter[ProductID] | None = Query(
None, title="ProductID Filter", description="Filter by product ID."
),
organization_id: MultipleQueryFilter[OrganizationID] | None = Query(
None, title="OrganizationID Filter", description="Filter by organization ID."
),
Expand All @@ -65,6 +68,7 @@ async def list(
results, count = await product_service.list(
session,
auth_subject,
id=id,
organization_id=organization_id,
query=query,
is_archived=is_archived,
Expand Down
4 changes: 4 additions & 0 deletions server/polar/product/service/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async def list(
session: AsyncSession,
auth_subject: AuthSubject[User | Organization],
*,
id: Sequence[uuid.UUID] | None = None,
organization_id: Sequence[uuid.UUID] | None = None,
query: str | None = None,
is_archived: bool | None = None,
Expand Down Expand Up @@ -91,6 +92,9 @@ async def list(
isouter=True,
)

if id is not None:
statement = statement.where(Product.id.in_(id))

if organization_id is not None:
statement = statement.where(Product.organization_id.in_(organization_id))

Expand Down

0 comments on commit ffcd491

Please sign in to comment.