-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'x/update-metadata-filter-type' into dev
- Loading branch information
Showing
1 changed file
with
8 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
import json | ||
from json import JSONDecodeError | ||
from typing import Annotated, Literal | ||
from uuid import UUID | ||
|
||
from fastapi import Depends, HTTPException, status | ||
from fastapi import Depends | ||
|
||
from ...autogen.openapi_model import ListResponse, User | ||
from ...dependencies.developer_id import get_developer_id | ||
from ...dependencies.query_filter import create_filter_extractor | ||
from ...models.user.list_users import list_users as list_users_query | ||
from .router import router | ||
|
||
|
||
@router.get("/users", tags=["users"]) | ||
async def list_users( | ||
x_developer_id: Annotated[UUID, Depends(get_developer_id)], | ||
metadata_filter: Annotated[ | ||
dict, Depends(create_filter_extractor("metadata_filter")) | ||
], | ||
limit: int = 100, | ||
offset: int = 0, | ||
sort_by: Literal["created_at", "updated_at"] = "created_at", | ||
direction: Literal["asc", "desc"] = "desc", | ||
metadata_filter: str = "{}", | ||
) -> ListResponse[User]: | ||
try: | ||
metadata_filter = json.loads(metadata_filter) | ||
except JSONDecodeError: | ||
raise HTTPException( | ||
status_code=status.HTTP_400_BAD_REQUEST, | ||
detail="metadata_filter is not a valid JSON", | ||
) | ||
|
||
users = list_users_query( | ||
developer_id=x_developer_id, | ||
limit=limit, | ||
offset=offset, | ||
sort_by=sort_by, | ||
direction=direction, | ||
metadata_filter=metadata_filter, | ||
metadata_filter=metadata_filter or {}, | ||
) | ||
|
||
result = ListResponse[User](items=users) | ||
return result | ||
return ListResponse[User](items=users) | ||
|