Skip to content

Commit ad72c4d

Browse files
estebanx64tiangolo
andauthored
♻️ Refactor rename ModelsOut to ModelsPublic (#1154)
Co-authored-by: Sebastián Ramírez <[email protected]>
1 parent 1105ea4 commit ad72c4d

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

backend/app/api/routes/items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from sqlmodel import func, select
55

66
from app.api.deps import CurrentUser, SessionDep
7-
from app.models import Item, ItemCreate, ItemOut, ItemsOut, ItemUpdate, Message
7+
from app.models import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate, Message
88

99
router = APIRouter()
1010

1111

12-
@router.get("/", response_model=ItemsOut)
12+
@router.get("/", response_model=ItemsPublic)
1313
def read_items(
1414
session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100
1515
) -> Any:
@@ -37,10 +37,10 @@ def read_items(
3737
)
3838
items = session.exec(statement).all()
3939

40-
return ItemsOut(data=items, count=count)
40+
return ItemsPublic(data=items, count=count)
4141

4242

43-
@router.get("/{id}", response_model=ItemOut)
43+
@router.get("/{id}", response_model=ItemPublic)
4444
def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any:
4545
"""
4646
Get item by ID.
@@ -53,7 +53,7 @@ def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any:
5353
return item
5454

5555

56-
@router.post("/", response_model=ItemOut)
56+
@router.post("/", response_model=ItemPublic)
5757
def create_item(
5858
*, session: SessionDep, current_user: CurrentUser, item_in: ItemCreate
5959
) -> Any:
@@ -67,7 +67,7 @@ def create_item(
6767
return item
6868

6969

70-
@router.put("/{id}", response_model=ItemOut)
70+
@router.put("/{id}", response_model=ItemPublic)
7171
def update_item(
7272
*, session: SessionDep, current_user: CurrentUser, id: int, item_in: ItemUpdate
7373
) -> Any:

backend/app/api/routes/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from app.core import security
1111
from app.core.config import settings
1212
from app.core.security import get_password_hash
13-
from app.models import Message, NewPassword, Token, UserOut
13+
from app.models import Message, NewPassword, Token, UserPublic
1414
from app.utils import (
1515
generate_password_reset_token,
1616
generate_reset_password_email,
@@ -43,7 +43,7 @@ def login_access_token(
4343
)
4444

4545

46-
@router.post("/login/test-token", response_model=UserOut)
46+
@router.post("/login/test-token", response_model=UserPublic)
4747
def test_token(current_user: CurrentUser) -> Any:
4848
"""
4949
Test access token

backend/app/api/routes/users.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
UpdatePassword,
1818
User,
1919
UserCreate,
20-
UserOut,
20+
UserPublic,
2121
UserRegister,
22-
UsersOut,
22+
UsersPublic,
2323
UserUpdate,
2424
UserUpdateMe,
2525
)
@@ -29,7 +29,9 @@
2929

3030

3131
@router.get(
32-
"/", dependencies=[Depends(get_current_active_superuser)], response_model=UsersOut
32+
"/",
33+
dependencies=[Depends(get_current_active_superuser)],
34+
response_model=UsersPublic,
3335
)
3436
def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
3537
"""
@@ -42,11 +44,11 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
4244
statement = select(User).offset(skip).limit(limit)
4345
users = session.exec(statement).all()
4446

45-
return UsersOut(data=users, count=count)
47+
return UsersPublic(data=users, count=count)
4648

4749

4850
@router.post(
49-
"/", dependencies=[Depends(get_current_active_superuser)], response_model=UserOut
51+
"/", dependencies=[Depends(get_current_active_superuser)], response_model=UserPublic
5052
)
5153
def create_user(*, session: SessionDep, user_in: UserCreate) -> Any:
5254
"""
@@ -72,7 +74,7 @@ def create_user(*, session: SessionDep, user_in: UserCreate) -> Any:
7274
return user
7375

7476

75-
@router.patch("/me", response_model=UserOut)
77+
@router.patch("/me", response_model=UserPublic)
7678
def update_user_me(
7779
*, session: SessionDep, user_in: UserUpdateMe, current_user: CurrentUser
7880
) -> Any:
@@ -114,15 +116,15 @@ def update_password_me(
114116
return Message(message="Password updated successfully")
115117

116118

117-
@router.get("/me", response_model=UserOut)
119+
@router.get("/me", response_model=UserPublic)
118120
def read_user_me(current_user: CurrentUser) -> Any:
119121
"""
120122
Get current user.
121123
"""
122124
return current_user
123125

124126

125-
@router.post("/signup", response_model=UserOut)
127+
@router.post("/signup", response_model=UserPublic)
126128
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
127129
"""
128130
Create new user without the need to be logged in.
@@ -143,7 +145,7 @@ def register_user(session: SessionDep, user_in: UserRegister) -> Any:
143145
return user
144146

145147

146-
@router.get("/{user_id}", response_model=UserOut)
148+
@router.get("/{user_id}", response_model=UserPublic)
147149
def read_user_by_id(
148150
user_id: int, session: SessionDep, current_user: CurrentUser
149151
) -> Any:
@@ -164,7 +166,7 @@ def read_user_by_id(
164166
@router.patch(
165167
"/{user_id}",
166168
dependencies=[Depends(get_current_active_superuser)],
167-
response_model=UserOut,
169+
response_model=UserPublic,
168170
)
169171
def update_user(
170172
*,

backend/app/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ class User(UserBase, table=True):
4848

4949

5050
# Properties to return via API, id is always required
51-
class UserOut(UserBase):
51+
class UserPublic(UserBase):
5252
id: int
5353

5454

55-
class UsersOut(SQLModel):
56-
data: list[UserOut]
55+
class UsersPublic(SQLModel):
56+
data: list[UserPublic]
5757
count: int
5858

5959

@@ -82,13 +82,13 @@ class Item(ItemBase, table=True):
8282

8383

8484
# Properties to return via API, id is always required
85-
class ItemOut(ItemBase):
85+
class ItemPublic(ItemBase):
8686
id: int
8787
owner_id: int
8888

8989

90-
class ItemsOut(SQLModel):
91-
data: list[ItemOut]
90+
class ItemsPublic(SQLModel):
91+
data: list[ItemPublic]
9292
count: int
9393

9494

0 commit comments

Comments
 (0)