Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions folksonomy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,35 @@ async def product_stats(

@app.get("/products", response_model=List[ProductList], tags=["Products"])
async def product_list(
response: Response, owner="", k="", v="", user: User = Depends(get_current_user)
response: Response,
k: str,
owner: str = "",
v: str = "",
code: str = Query(
None, description="Comma-separated list of product code to filter by"
),
user: User = Depends(get_current_user),
):
"""
Get the list of products matching k or k=v
Get the list of products matching k or k=v, optionally filtered by specific product code

- **k**: Property name (required)
- **owner**: Owner filter (optional, default empty for public)
- **v**: Property value filter (optional)
- **code**: Comma-separated list of product code to filter by (optional)
"""
if k == "":
return JSONResponse(
status_code=422, content={"detail": {"msg": "missing value for k"}}
)
check_owner_user(user, owner, allow_anonymous=True)
k, v = sanitize_data(k, v)
where, params = property_where(owner, k, v)

# Add product ID filter if code is provided
if code:
product_code = [pid.strip() for pid in code.split(",") if pid.strip()]
if product_code:
placeholders = ", ".join(["%s"] * len(product_code))
where += f" AND product IN ({placeholders})"
params.extend(product_code)

cur, timing = await db.db_exec(
"""
SELECT coalesce(json_agg(j.j)::json, '[]'::json) FROM(
Expand Down
Loading