From 31e68148dd27ba8928da3b70796fc289b80f1619 Mon Sep 17 00:00:00 2001 From: Diwank Tomer Date: Mon, 1 Jul 2024 09:34:44 -0700 Subject: [PATCH] feat(agents-api): Refactor routers.py files Signed-off-by: Diwank Tomer --- .../agents_api/autogen/openapi_model.py | 2 +- .../agents_api/routers/agents/__init__.py | 9 ++++-- .../agents_api/routers/agents/create_agent.py | 17 ++++++----- .../agents_api/routers/agents/delete_agent.py | 23 +++++++-------- .../routers/agents/get_agent_details.py | 22 +++++++-------- .../agents_api/routers/agents/list_agents.py | 14 ++++++---- .../agents_api/routers/agents/patch_agent.py | 27 ++++++++++-------- .../agents_api/routers/agents/router.py | 3 ++ .../agents_api/routers/agents/update_agent.py | 27 ++++++++++-------- .../agents_api/routers/sessions/__init__.py | 9 ++++-- .../routers/sessions/create_session.py | 19 +++++++++---- .../routers/sessions/delete_session.py | 28 ++++++++++--------- .../routers/sessions/get_session.py | 14 ++++++---- .../routers/sessions/list_sessions.py | 18 ++++++++---- .../routers/sessions/patch_session.py | 18 ++++++++---- .../agents_api/routers/sessions/router.py | 3 ++ .../routers/sessions/update_session.py | 18 ++++++++---- .../agents_api/routers/users/__init__.py | 8 ++++-- .../agents_api/routers/users/create_user.py | 22 ++++++++------- .../agents_api/routers/users/delete_user.py | 25 ----------------- .../routers/users/get_user_details.py | 17 ++++++----- .../agents_api/routers/users/list_users.py | 16 +++++++---- .../agents_api/routers/users/patch_user.py | 20 ++++++------- agents-api/agents_api/routers/users/router.py | 3 ++ .../agents_api/routers/users/update_user.py | 20 ++++++------- 25 files changed, 227 insertions(+), 175 deletions(-) create mode 100644 agents-api/agents_api/routers/agents/router.py create mode 100644 agents-api/agents_api/routers/sessions/router.py delete mode 100644 agents-api/agents_api/routers/users/delete_user.py create mode 100644 agents-api/agents_api/routers/users/router.py diff --git a/agents-api/agents_api/autogen/openapi_model.py b/agents-api/agents_api/autogen/openapi_model.py index 68d0d0901..b005969fd 100644 --- a/agents-api/agents_api/autogen/openapi_model.py +++ b/agents-api/agents_api/autogen/openapi_model.py @@ -837,7 +837,7 @@ class ImageUrl(BaseModel): """ URL or base64 data url (e.g. `data:image/jpeg;base64,`) """ - detail: Detail | None = "auto" + detail: Detail | None = "auto" # pytype: disable=annotation-type-mismatch """ image detail to feed into the model can be low | high | auto """ diff --git a/agents-api/agents_api/routers/agents/__init__.py b/agents-api/agents_api/routers/agents/__init__.py index af9233c56..ee2961f1b 100644 --- a/agents-api/agents_api/routers/agents/__init__.py +++ b/agents-api/agents_api/routers/agents/__init__.py @@ -1,3 +1,8 @@ -from fastapi import APIRouter +from .router import router # noqa: F401 -router = APIRouter() +from .create_agent import create_agent # noqa: F401 +from .delete_agent import delete_agent # noqa: F401 +from .get_agent_details import get_agent_details # noqa: F401 +from .list_agents import list_agents # noqa: F401 +from .update_agent import update_agent # noqa: F401 +from .patch_agent import patch_agent # noqa: F401 diff --git a/agents-api/agents_api/routers/agents/create_agent.py b/agents-api/agents_api/routers/agents/create_agent.py index f0f81a6c9..991a6a437 100644 --- a/agents-api/agents_api/routers/agents/create_agent.py +++ b/agents-api/agents_api/routers/agents/create_agent.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, Depends, HTTPException, status -from pydantic import UUID4 from typing import Annotated -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.create_agent import create_agent_query -from agents_api.autogen.openapi_model import CreateAgentRequest, ResourceCreatedResponse -from agents_api.common.utils.datetime import utcnow +from fastapi import Depends +from pydantic import UUID4 +from starlette.status import HTTP_201_CREATED + +from ...dependencies.developer_id import get_developer_id +from ...models.agent.create_agent import create_agent_query +from ...autogen.openapi_model import CreateAgentRequest, ResourceCreatedResponse +from ...common.utils.datetime import utcnow + +from .router import router -router = APIRouter() @router.post("/agents", status_code=HTTP_201_CREATED, tags=["agents"]) async def create_agent( diff --git a/agents-api/agents_api/routers/agents/delete_agent.py b/agents-api/agents_api/routers/agents/delete_agent.py index bfe7da8e2..2183d6bf3 100644 --- a/agents-api/agents_api/routers/agents/delete_agent.py +++ b/agents-api/agents_api/routers/agents/delete_agent.py @@ -1,14 +1,17 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 -from starlette.status import HTTP_202_ACCEPTED +from starlette.status import HTTP_202_ACCEPTED, HTTP_404_NOT_FOUND + +from ...dependencies.developer_id import get_developer_id +from ...models.agent.delete_agent import delete_agent_query +from ...common.exceptions.agents import AgentNotFoundError +from ...common.utils.datetime import utcnow +from ...autogen.openapi_model import ResourceDeletedResponse -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.delete_agent import delete_agent_query -from agents_api.common.exceptions.agents import AgentNotFoundError -from agents_api.common.utils.datetime import utcnow -from agents_api.autogen.openapi_model import ResourceDeletedResponse +from .router import router -router = APIRouter() @router.delete("/agents/{agent_id}", status_code=HTTP_202_ACCEPTED, tags=["agents"]) async def delete_agent( @@ -17,7 +20,5 @@ async def delete_agent( try: delete_agent_query(x_developer_id, agent_id) except AgentNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) return ResourceDeletedResponse(id=agent_id, deleted_at=utcnow()) diff --git a/agents-api/agents_api/routers/agents/get_agent_details.py b/agents-api/agents_api/routers/agents/get_agent_details.py index adaf9bbd1..174bb63b4 100644 --- a/agents-api/agents_api/routers/agents/get_agent_details.py +++ b/agents-api/agents_api/routers/agents/get_agent_details.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.get_agent import get_agent_query -from agents_api.common.exceptions.agents import AgentNotFoundError -from agents_api.autogen.openapi_model import Agent +from ...dependencies.developer_id import get_developer_id +from ...models.agent.get_agent import get_agent_query +from ...common.exceptions.agents import AgentNotFoundError +from ...autogen.openapi_model import Agent + +from .router import router -router = APIRouter() @router.get("/agents/{agent_id}", tags=["agents"]) async def get_agent_details( @@ -17,10 +20,7 @@ async def get_agent_details( try: agent = get_agent_query(developer_id=x_developer_id, agent_id=agent_id) if not agent: - raise AgentNotFoundError(f"Agent with ID {agent_id} not found") + raise AgentNotFoundError(x_developer_id, agent_id) return Agent(**agent) except AgentNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) diff --git a/agents-api/agents_api/routers/agents/list_agents.py b/agents-api/agents_api/routers/agents/list_agents.py index a21398d86..0001aad89 100644 --- a/agents-api/agents_api/routers/agents/list_agents.py +++ b/agents-api/agents_api/routers/agents/list_agents.py @@ -1,12 +1,14 @@ -from fastapi import APIRouter, Depends +from typing import List, Annotated + +from fastapi import Depends from pydantic import UUID4 -from typing import List -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.list_agents import list_agents_query -from agents_api.autogen.openapi_model import Agent +from ...dependencies.developer_id import get_developer_id +from ...models.agent.list_agents import list_agents_query +from ...autogen.openapi_model import Agent + +from .router import router -router = APIRouter() @router.get("/agents", tags=["agents"]) async def list_agents( diff --git a/agents-api/agents_api/routers/agents/patch_agent.py b/agents-api/agents_api/routers/agents/patch_agent.py index 3fe0d1946..5571fb67f 100644 --- a/agents-api/agents_api/routers/agents/patch_agent.py +++ b/agents-api/agents_api/routers/agents/patch_agent.py @@ -1,15 +1,23 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND, HTTP_200_OK -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.patch_agent import patch_agent_query -from agents_api.common.exceptions.agents import AgentNotFoundError -from agents_api.autogen.openapi_model import PatchAgentRequest, ResourceUpdatedResponse +from ...dependencies.developer_id import get_developer_id +from ...models.agent.patch_agent import patch_agent_query +from ...common.exceptions.agents import AgentNotFoundError +from ...autogen.openapi_model import PatchAgentRequest, ResourceUpdatedResponse + +from .router import router -router = APIRouter() -@router.patch("/agents/{agent_id}", response_model=ResourceUpdatedResponse, status_code=HTTP_200_OK, tags=["agents"]) +@router.patch( + "/agents/{agent_id}", + response_model=ResourceUpdatedResponse, + status_code=HTTP_200_OK, + tags=["agents"], +) async def patch_agent( agent_id: UUID4, request: PatchAgentRequest, @@ -28,7 +36,4 @@ async def patch_agent( ) return ResourceUpdatedResponse(**updated_agent) except AgentNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) diff --git a/agents-api/agents_api/routers/agents/router.py b/agents-api/agents_api/routers/agents/router.py new file mode 100644 index 000000000..af9233c56 --- /dev/null +++ b/agents-api/agents_api/routers/agents/router.py @@ -0,0 +1,3 @@ +from fastapi import APIRouter + +router = APIRouter() diff --git a/agents-api/agents_api/routers/agents/update_agent.py b/agents-api/agents_api/routers/agents/update_agent.py index 9dde0939a..0e254131c 100644 --- a/agents-api/agents_api/routers/agents/update_agent.py +++ b/agents-api/agents_api/routers/agents/update_agent.py @@ -1,15 +1,23 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND, HTTP_200_OK -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.agent.update_agent import update_agent_query -from agents_api.common.exceptions.agents import AgentNotFoundError -from agents_api.autogen.openapi_model import UpdateAgentRequest, ResourceUpdatedResponse +from ...dependencies.developer_id import get_developer_id +from ...models.agent.update_agent import update_agent_query +from ...common.exceptions.agents import AgentNotFoundError +from ...autogen.openapi_model import UpdateAgentRequest, ResourceUpdatedResponse + +from .router import router -router = APIRouter() -@router.put("/agents/{agent_id}", response_model=ResourceUpdatedResponse, status_code=HTTP_200_OK, tags=["agents"]) +@router.put( + "/agents/{agent_id}", + response_model=ResourceUpdatedResponse, + status_code=HTTP_200_OK, + tags=["agents"], +) async def update_agent( agent_id: UUID4, request: UpdateAgentRequest, @@ -28,7 +36,4 @@ async def update_agent( ) return ResourceUpdatedResponse(**updated_agent) except AgentNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) diff --git a/agents-api/agents_api/routers/sessions/__init__.py b/agents-api/agents_api/routers/sessions/__init__.py index af9233c56..a379a97f7 100644 --- a/agents-api/agents_api/routers/sessions/__init__.py +++ b/agents-api/agents_api/routers/sessions/__init__.py @@ -1,3 +1,8 @@ -from fastapi import APIRouter +from .router import router # noqa: F401 -router = APIRouter() +from .create_session import create_session # noqa: F401 +from .delete_session import delete_session # noqa: F401 +from .get_session import get_session # noqa: F401 +from .list_sessions import list_sessions # noqa: F401 +from .update_session import update_session # noqa: F401 +from .patch_session import patch_session # noqa: F401 diff --git a/agents-api/agents_api/routers/sessions/create_session.py b/agents-api/agents_api/routers/sessions/create_session.py index 76ade50da..f3fe3102a 100644 --- a/agents-api/agents_api/routers/sessions/create_session.py +++ b/agents-api/agents_api/routers/sessions/create_session.py @@ -1,13 +1,20 @@ -from fastapi import APIRouter, HTTPException, status, Depends -from pydantic import BaseModel, UUID4 from typing import Annotated from uuid import uuid4 -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.create_session import create_session_query -from agents_api.autogen.openapi_model import CreateSessionRequest, ResourceCreatedResponse +from fastapi import Depends +from pydantic import UUID4 +import pandas as pd +from starlette.status import HTTP_201_CREATED + +from ...dependencies.developer_id import get_developer_id +from ...models.session.create_session import create_session_query +from ...autogen.openapi_model import ( + CreateSessionRequest, + ResourceCreatedResponse, +) + +from .router import router -router = APIRouter() @router.post("/sessions", status_code=HTTP_201_CREATED, tags=["sessions"]) async def create_session( diff --git a/agents-api/agents_api/routers/sessions/delete_session.py b/agents-api/agents_api/routers/sessions/delete_session.py index 8ba77a986..a910bc991 100644 --- a/agents-api/agents_api/routers/sessions/delete_session.py +++ b/agents-api/agents_api/routers/sessions/delete_session.py @@ -1,25 +1,27 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 -from starlette.status import HTTP_202_ACCEPTED +from starlette.status import HTTP_202_ACCEPTED, HTTP_404_NOT_FOUND + +from ...autogen.openapi_model import ResourceDeletedResponse +from ...common.exceptions.sessions import SessionNotFoundError +from ...common.utils.datetime import utcnow +from ...dependencies.developer_id import get_developer_id +from ...models.session.delete_session import delete_session_query -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.delete_session import delete_session_query -from agents_api.common.exceptions.sessions import SessionNotFoundError -from agents_api.autogen.openapi_model import ResourceDeletedResponse -from agents_api.common.utils.datetime import utcnow +from .router import router -router = APIRouter() -@router.delete("/sessions/{session_id}", status_code=HTTP_202_ACCEPTED, tags=["sessions"]) +@router.delete( + "/sessions/{session_id}", status_code=HTTP_202_ACCEPTED, tags=["sessions"] +) async def delete_session( session_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)] ) -> ResourceDeletedResponse: try: delete_session_query(x_developer_id, session_id) except SessionNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) return ResourceDeletedResponse(id=session_id, deleted_at=utcnow()) diff --git a/agents-api/agents_api/routers/sessions/get_session.py b/agents-api/agents_api/routers/sessions/get_session.py index 49279e0d6..4f9ef4d2a 100644 --- a/agents-api/agents_api/routers/sessions/get_session.py +++ b/agents-api/agents_api/routers/sessions/get_session.py @@ -1,12 +1,14 @@ -from fastapi import APIRouter, Depends, HTTPException -from pydantic import UUID4 from typing import Annotated -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.get_session import get_session_query -from agents_api.autogen.openapi_model import Session +from fastapi import Depends, HTTPException +from pydantic import UUID4 + +from ...dependencies.developer_id import get_developer_id +from ...models.session.get_session import get_session_query +from ...autogen.openapi_model import Session + +from .router import router -router = APIRouter() @router.get("/sessions/{session_id}", tags=["sessions"]) async def get_session( diff --git a/agents-api/agents_api/routers/sessions/list_sessions.py b/agents-api/agents_api/routers/sessions/list_sessions.py index ec125116f..bfc9d4548 100644 --- a/agents-api/agents_api/routers/sessions/list_sessions.py +++ b/agents-api/agents_api/routers/sessions/list_sessions.py @@ -1,15 +1,21 @@ -from fastapi import APIRouter, Depends +import json +from json import JSONDecodeError from typing import Annotated -from pydantic import UUID4 -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.list_sessions import list_sessions_query -from agents_api.autogen.openapi_model import Session -router = APIRouter() +from fastapi import Depends, HTTPException, status +from pydantic import UUID4, BaseModel + +from ...dependencies.developer_id import get_developer_id +from ...models.session.list_sessions import list_sessions_query +from ...autogen.openapi_model import Session + +from .router import router + class SessionList(BaseModel): items: list[Session] + @router.get("/sessions", tags=["sessions"]) async def list_sessions( x_developer_id: Annotated[UUID4, Depends(get_developer_id)], diff --git a/agents-api/agents_api/routers/sessions/patch_session.py b/agents-api/agents_api/routers/sessions/patch_session.py index 8f6ee7d21..53bae98f3 100644 --- a/agents-api/agents_api/routers/sessions/patch_session.py +++ b/agents-api/agents_api/routers/sessions/patch_session.py @@ -1,13 +1,19 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.patch_session import patch_session_query -from agents_api.autogen.openapi_model import PatchSessionRequest, ResourceUpdatedResponse -from agents_api.common.exceptions.sessions import SessionNotFoundError +from ...common.exceptions.sessions import SessionNotFoundError +from ...dependencies.developer_id import get_developer_id +from ...models.session.patch_session import patch_session_query +from ...autogen.openapi_model import ( + PatchSessionRequest, + ResourceUpdatedResponse, +) + +from .router import router -router = APIRouter() @router.patch("/sessions/{session_id}", tags=["sessions"]) async def patch_session( diff --git a/agents-api/agents_api/routers/sessions/router.py b/agents-api/agents_api/routers/sessions/router.py new file mode 100644 index 000000000..af9233c56 --- /dev/null +++ b/agents-api/agents_api/routers/sessions/router.py @@ -0,0 +1,3 @@ +from fastapi import APIRouter + +router = APIRouter() diff --git a/agents-api/agents_api/routers/sessions/update_session.py b/agents-api/agents_api/routers/sessions/update_session.py index 921da89f1..eab921c8b 100644 --- a/agents-api/agents_api/routers/sessions/update_session.py +++ b/agents-api/agents_api/routers/sessions/update_session.py @@ -1,13 +1,19 @@ -from fastapi import APIRouter, Depends, HTTPException +from typing import Annotated + +from fastapi import Depends, HTTPException from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.session.update_session import update_session_query -from agents_api.autogen.openapi_model import UpdateSessionRequest, ResourceUpdatedResponse -from agents_api.common.exceptions.sessions import SessionNotFoundError +from ...common.exceptions.sessions import SessionNotFoundError +from ...dependencies.developer_id import get_developer_id +from ...models.session.update_session import update_session_query +from ...autogen.openapi_model import ( + UpdateSessionRequest, + ResourceUpdatedResponse, +) + +from .router import router -router = APIRouter() @router.put("/sessions/{session_id}", tags=["sessions"]) async def update_session( diff --git a/agents-api/agents_api/routers/users/__init__.py b/agents-api/agents_api/routers/users/__init__.py index af9233c56..9c8bfa7dc 100644 --- a/agents-api/agents_api/routers/users/__init__.py +++ b/agents-api/agents_api/routers/users/__init__.py @@ -1,3 +1,7 @@ -from fastapi import APIRouter +from .router import router # noqa: F401 -router = APIRouter() +from .create_user import create_user # noqa: F401 +from .get_user_details import get_user_details # noqa: F401 +from .list_users import list_users # noqa: F401 +from .update_user import update_user # noqa: F401 +from .patch_user import patch_user # noqa: F401 diff --git a/agents-api/agents_api/routers/users/create_user.py b/agents-api/agents_api/routers/users/create_user.py index c32b4b5bb..024c26822 100644 --- a/agents-api/agents_api/routers/users/create_user.py +++ b/agents-api/agents_api/routers/users/create_user.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, HTTPException, status, Depends -from pydantic import BaseModel, UUID4 -from typing import Optional +from typing import Annotated from uuid import uuid4 -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.user.create_user import create_user_query -from agents_api.autogen.openapi_model import CreateUserRequest, ResourceCreatedResponse +from fastapi import Depends +from pydantic import UUID4 +from starlette.status import HTTP_201_CREATED + +from ...dependencies.developer_id import get_developer_id +from ...models.user.create_user import create_user_query +from ...autogen.openapi_model import CreateUserRequest, ResourceCreatedResponse + +from .router import router -router = APIRouter() @router.post("/users", status_code=HTTP_201_CREATED, tags=["users"]) async def create_user( @@ -20,9 +23,8 @@ async def create_user( user_id=user_id, name=request.name, about=request.about, - metadata=request.metadata + metadata=request.metadata, ) return ResourceCreatedResponse( - id=str(user_id), - created_at=created_user["created_at"] + id=str(user_id), created_at=created_user["created_at"] ) diff --git a/agents-api/agents_api/routers/users/delete_user.py b/agents-api/agents_api/routers/users/delete_user.py deleted file mode 100644 index d64549573..000000000 --- a/agents-api/agents_api/routers/users/delete_user.py +++ /dev/null @@ -1,25 +0,0 @@ -from fastapi import APIRouter, HTTPException, Depends -from pydantic import UUID4 -from starlette.status import HTTP_202_ACCEPTED - -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.common.exceptions.users import UserNotFoundError -from agents_api.models.user.delete_user import delete_user_query -from agents_api.autogen.openapi_model import ResourceDeletedResponse -from agents_api.common.utils.datetime import utcnow - -router = APIRouter() - -@router.delete("/users/{user_id}", status_code=HTTP_202_ACCEPTED, tags=["users"]) -async def delete_user( - user_id: UUID4, x_developer_id: Annotated[UUID4, Depends(get_developer_id)] -) -> ResourceDeletedResponse: - try: - delete_user_query(x_developer_id, user_id) - except UserNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) - - return ResourceDeletedResponse(id=user_id, deleted_at=utcnow()) diff --git a/agents-api/agents_api/routers/users/get_user_details.py b/agents-api/agents_api/routers/users/get_user_details.py index 5150bedc1..4fea6551b 100644 --- a/agents-api/agents_api/routers/users/get_user_details.py +++ b/agents-api/agents_api/routers/users/get_user_details.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, HTTPException, Depends -from pydantic import UUID4 from typing import Annotated -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.user.get_user import get_user_query -from agents_api.autogen.openapi_model import User -from agents_api.common.exceptions.users import UserNotFoundError +from fastapi import HTTPException, Depends, status +from pycozo.client import QueryException +from pydantic import UUID4 + +from ...dependencies.developer_id import get_developer_id +from ...models.user.get_user import get_user_query +from ...autogen.openapi_model import User +from ...common.exceptions.users import UserNotFoundError + +from .router import router -router = APIRouter() @router.get("/users/{user_id}", tags=["users"]) async def get_user_details( diff --git a/agents-api/agents_api/routers/users/list_users.py b/agents-api/agents_api/routers/users/list_users.py index d1e1679e8..933749abf 100644 --- a/agents-api/agents_api/routers/users/list_users.py +++ b/agents-api/agents_api/routers/users/list_users.py @@ -1,12 +1,16 @@ -from fastapi import APIRouter, HTTPException, Depends -from pydantic import UUID4 +import json +from json import JSONDecodeError from typing import Annotated, List -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.models.user.list_users import list_users_query -from agents_api.autogen.openapi_model import User +from fastapi import HTTPException, Depends, status +from pydantic import UUID4 + +from ...dependencies.developer_id import get_developer_id +from ...models.user.list_users import list_users_query +from ...autogen.openapi_model import User + +from .router import router -router = APIRouter() @router.get("/users", tags=["users"]) async def list_users( diff --git a/agents-api/agents_api/routers/users/patch_user.py b/agents-api/agents_api/routers/users/patch_user.py index 097126266..cbcd7940a 100644 --- a/agents-api/agents_api/routers/users/patch_user.py +++ b/agents-api/agents_api/routers/users/patch_user.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, HTTPException, Depends +from typing import Annotated + +from fastapi import HTTPException, Depends from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.common.exceptions.users import UserNotFoundError -from agents_api.models.user.patch_user import patch_user_query -from agents_api.autogen.openapi_model import PatchUserRequest, ResourceUpdatedResponse +from ...dependencies.developer_id import get_developer_id +from ...common.exceptions.users import UserNotFoundError +from ...models.user.patch_user import patch_user_query +from ...autogen.openapi_model import PatchUserRequest, ResourceUpdatedResponse + +from .router import router -router = APIRouter() @router.patch("/users/{user_id}", tags=["users"]) async def patch_user( @@ -34,7 +37,4 @@ async def patch_user( detail="User not found", ) except UserNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e)) diff --git a/agents-api/agents_api/routers/users/router.py b/agents-api/agents_api/routers/users/router.py new file mode 100644 index 000000000..af9233c56 --- /dev/null +++ b/agents-api/agents_api/routers/users/router.py @@ -0,0 +1,3 @@ +from fastapi import APIRouter + +router = APIRouter() diff --git a/agents-api/agents_api/routers/users/update_user.py b/agents-api/agents_api/routers/users/update_user.py index 0b4fe0926..725939eeb 100644 --- a/agents-api/agents_api/routers/users/update_user.py +++ b/agents-api/agents_api/routers/users/update_user.py @@ -1,13 +1,16 @@ -from fastapi import APIRouter, HTTPException, Depends +from typing import Annotated + +from fastapi import HTTPException, Depends from pydantic import UUID4 from starlette.status import HTTP_404_NOT_FOUND -from agents_api.dependencies.developer_id import get_developer_id -from agents_api.common.exceptions.users import UserNotFoundError -from agents_api.models.user.update_user import update_user_query -from agents_api.autogen.openapi_model import UpdateUserRequest, ResourceUpdatedResponse +from ...dependencies.developer_id import get_developer_id +from ...common.exceptions.users import UserNotFoundError +from ...models.user.update_user import update_user_query +from ...autogen.openapi_model import UpdateUserRequest, ResourceUpdatedResponse + +from .router import router -router = APIRouter() @router.put("/users/{user_id}", tags=["users"]) async def update_user( @@ -34,7 +37,4 @@ async def update_user( detail="User not found", ) except UserNotFoundError as e: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=str(e) - ) + raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=str(e))