From 8e8b491aeba716649809a2fefe707dfc91c9d79e Mon Sep 17 00:00:00 2001 From: Esteban Maya Date: Sat, 6 Apr 2024 16:53:49 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20rename=20Models?= =?UTF-8?q?Out=20to=20ModelsPublic=20(#1154)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- backend/app/api/routes/items.py | 12 ++++++------ backend/app/api/routes/login.py | 4 ++-- backend/app/api/routes/users.py | 22 ++++++++++++---------- backend/app/models.py | 12 ++++++------ 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index beb0b816b81..7e068799612 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -4,12 +4,12 @@ from sqlmodel import func, select from app.api.deps import CurrentUser, SessionDep -from app.models import Item, ItemCreate, ItemOut, ItemsOut, ItemUpdate, Message +from app.models import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate, Message router = APIRouter() -@router.get("/", response_model=ItemsOut) +@router.get("/", response_model=ItemsPublic) def read_items( session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100 ) -> Any: @@ -37,10 +37,10 @@ def read_items( ) items = session.exec(statement).all() - return ItemsOut(data=items, count=count) + return ItemsPublic(data=items, count=count) -@router.get("/{id}", response_model=ItemOut) +@router.get("/{id}", response_model=ItemPublic) def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any: """ Get item by ID. @@ -53,7 +53,7 @@ def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any: return item -@router.post("/", response_model=ItemOut) +@router.post("/", response_model=ItemPublic) def create_item( *, session: SessionDep, current_user: CurrentUser, item_in: ItemCreate ) -> Any: @@ -67,7 +67,7 @@ def create_item( return item -@router.put("/{id}", response_model=ItemOut) +@router.put("/{id}", response_model=ItemPublic) def update_item( *, session: SessionDep, current_user: CurrentUser, id: int, item_in: ItemUpdate ) -> Any: diff --git a/backend/app/api/routes/login.py b/backend/app/api/routes/login.py index ad78a2d3ab2..fe7e94d5c13 100644 --- a/backend/app/api/routes/login.py +++ b/backend/app/api/routes/login.py @@ -10,7 +10,7 @@ from app.core import security from app.core.config import settings from app.core.security import get_password_hash -from app.models import Message, NewPassword, Token, UserOut +from app.models import Message, NewPassword, Token, UserPublic from app.utils import ( generate_password_reset_token, generate_reset_password_email, @@ -43,7 +43,7 @@ def login_access_token( ) -@router.post("/login/test-token", response_model=UserOut) +@router.post("/login/test-token", response_model=UserPublic) def test_token(current_user: CurrentUser) -> Any: """ Test access token diff --git a/backend/app/api/routes/users.py b/backend/app/api/routes/users.py index 0a302157223..1fd25000a68 100644 --- a/backend/app/api/routes/users.py +++ b/backend/app/api/routes/users.py @@ -17,9 +17,9 @@ UpdatePassword, User, UserCreate, - UserOut, + UserPublic, UserRegister, - UsersOut, + UsersPublic, UserUpdate, UserUpdateMe, ) @@ -29,7 +29,9 @@ @router.get( - "/", dependencies=[Depends(get_current_active_superuser)], response_model=UsersOut + "/", + dependencies=[Depends(get_current_active_superuser)], + response_model=UsersPublic, ) def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any: """ @@ -42,11 +44,11 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any: statement = select(User).offset(skip).limit(limit) users = session.exec(statement).all() - return UsersOut(data=users, count=count) + return UsersPublic(data=users, count=count) @router.post( - "/", dependencies=[Depends(get_current_active_superuser)], response_model=UserOut + "/", dependencies=[Depends(get_current_active_superuser)], response_model=UserPublic ) def create_user(*, session: SessionDep, user_in: UserCreate) -> Any: """ @@ -72,7 +74,7 @@ def create_user(*, session: SessionDep, user_in: UserCreate) -> Any: return user -@router.patch("/me", response_model=UserOut) +@router.patch("/me", response_model=UserPublic) def update_user_me( *, session: SessionDep, user_in: UserUpdateMe, current_user: CurrentUser ) -> Any: @@ -114,7 +116,7 @@ def update_password_me( return Message(message="Password updated successfully") -@router.get("/me", response_model=UserOut) +@router.get("/me", response_model=UserPublic) def read_user_me(current_user: CurrentUser) -> Any: """ Get current user. @@ -122,7 +124,7 @@ def read_user_me(current_user: CurrentUser) -> Any: return current_user -@router.post("/signup", response_model=UserOut) +@router.post("/signup", response_model=UserPublic) def register_user(session: SessionDep, user_in: UserRegister) -> Any: """ Create new user without the need to be logged in. @@ -143,7 +145,7 @@ def register_user(session: SessionDep, user_in: UserRegister) -> Any: return user -@router.get("/{user_id}", response_model=UserOut) +@router.get("/{user_id}", response_model=UserPublic) def read_user_by_id( user_id: int, session: SessionDep, current_user: CurrentUser ) -> Any: @@ -164,7 +166,7 @@ def read_user_by_id( @router.patch( "/{user_id}", dependencies=[Depends(get_current_active_superuser)], - response_model=UserOut, + response_model=UserPublic, ) def update_user( *, diff --git a/backend/app/models.py b/backend/app/models.py index 16221a6fc27..8e74fea7fcc 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -48,12 +48,12 @@ class User(UserBase, table=True): # Properties to return via API, id is always required -class UserOut(UserBase): +class UserPublic(UserBase): id: int -class UsersOut(SQLModel): - data: list[UserOut] +class UsersPublic(SQLModel): + data: list[UserPublic] count: int @@ -82,13 +82,13 @@ class Item(ItemBase, table=True): # Properties to return via API, id is always required -class ItemOut(ItemBase): +class ItemPublic(ItemBase): id: int owner_id: int -class ItemsOut(SQLModel): - data: list[ItemOut] +class ItemsPublic(SQLModel): + data: list[ItemPublic] count: int