Skip to content

Commit

Permalink
Merge branch 'x/update-metadata-filter-type' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr committed Oct 5, 2024
2 parents 2e0108e + 196b827 commit e2bda99
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions agents-api/agents_api/routers/users/list_users.py
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)

0 comments on commit e2bda99

Please sign in to comment.