🔧 fix(store.py): add count_components endpoint to retrieve the count of components in the store
🔧 fix(service.py): modify count_components method to make api_key optional and add filter_by_user parameter to filter components by user
This commit is contained in:
parent
3934096e06
commit
785e8a6436
2 changed files with 16 additions and 1 deletions
|
|
@ -78,6 +78,21 @@ def list_components(
|
|||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/components/count", response_model=dict)
|
||||
def count_components(
|
||||
filter_by_user: bool = Query(False),
|
||||
store_service: StoreService = Depends(get_store_service),
|
||||
store_api_Key: str = Depends(get_optional_user_store_api_key),
|
||||
):
|
||||
try:
|
||||
result = store_service.count_components(
|
||||
api_key=store_api_Key, filter_by_user=filter_by_user
|
||||
)
|
||||
return {"count": result}
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
|
||||
@router.get("/components/{component_id}", response_model=DownloadComponentResponse)
|
||||
def read_component(
|
||||
component_id: UUID,
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class StoreService(Service):
|
|||
|
||||
def count_components(
|
||||
self,
|
||||
api_key: str,
|
||||
api_key: Optional[str] = None,
|
||||
filter_by_user: bool = False,
|
||||
) -> int:
|
||||
params = {"aggregate": json.dumps({"count": "*"})}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue