♻️ Refactor rename ModelsOut to ModelsPublic (#1154)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -4,12 +4,12 @@ from fastapi import APIRouter, HTTPException
|
|||||||
from sqlmodel import func, select
|
from sqlmodel import func, select
|
||||||
|
|
||||||
from app.api.deps import CurrentUser, SessionDep
|
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 = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/", response_model=ItemsOut)
|
@router.get("/", response_model=ItemsPublic)
|
||||||
def read_items(
|
def read_items(
|
||||||
session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100
|
session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100
|
||||||
) -> Any:
|
) -> Any:
|
||||||
@@ -37,10 +37,10 @@ def read_items(
|
|||||||
)
|
)
|
||||||
items = session.exec(statement).all()
|
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:
|
def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any:
|
||||||
"""
|
"""
|
||||||
Get item by ID.
|
Get item by ID.
|
||||||
@@ -53,7 +53,7 @@ def read_item(session: SessionDep, current_user: CurrentUser, id: int) -> Any:
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
@router.post("/", response_model=ItemOut)
|
@router.post("/", response_model=ItemPublic)
|
||||||
def create_item(
|
def create_item(
|
||||||
*, session: SessionDep, current_user: CurrentUser, item_in: ItemCreate
|
*, session: SessionDep, current_user: CurrentUser, item_in: ItemCreate
|
||||||
) -> Any:
|
) -> Any:
|
||||||
@@ -67,7 +67,7 @@ def create_item(
|
|||||||
return item
|
return item
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{id}", response_model=ItemOut)
|
@router.put("/{id}", response_model=ItemPublic)
|
||||||
def update_item(
|
def update_item(
|
||||||
*, session: SessionDep, current_user: CurrentUser, id: int, item_in: ItemUpdate
|
*, session: SessionDep, current_user: CurrentUser, id: int, item_in: ItemUpdate
|
||||||
) -> Any:
|
) -> Any:
|
||||||
|
@@ -10,7 +10,7 @@ from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser
|
|||||||
from app.core import security
|
from app.core import security
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.security import get_password_hash
|
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 (
|
from app.utils import (
|
||||||
generate_password_reset_token,
|
generate_password_reset_token,
|
||||||
generate_reset_password_email,
|
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:
|
def test_token(current_user: CurrentUser) -> Any:
|
||||||
"""
|
"""
|
||||||
Test access token
|
Test access token
|
||||||
|
@@ -17,9 +17,9 @@ from app.models import (
|
|||||||
UpdatePassword,
|
UpdatePassword,
|
||||||
User,
|
User,
|
||||||
UserCreate,
|
UserCreate,
|
||||||
UserOut,
|
UserPublic,
|
||||||
UserRegister,
|
UserRegister,
|
||||||
UsersOut,
|
UsersPublic,
|
||||||
UserUpdate,
|
UserUpdate,
|
||||||
UserUpdateMe,
|
UserUpdateMe,
|
||||||
)
|
)
|
||||||
@@ -29,7 +29,9 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
@router.get(
|
@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:
|
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)
|
statement = select(User).offset(skip).limit(limit)
|
||||||
users = session.exec(statement).all()
|
users = session.exec(statement).all()
|
||||||
|
|
||||||
return UsersOut(data=users, count=count)
|
return UsersPublic(data=users, count=count)
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@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:
|
def create_user(*, session: SessionDep, user_in: UserCreate) -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -72,7 +74,7 @@ def create_user(*, session: SessionDep, user_in: UserCreate) -> Any:
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@router.patch("/me", response_model=UserOut)
|
@router.patch("/me", response_model=UserPublic)
|
||||||
def update_user_me(
|
def update_user_me(
|
||||||
*, session: SessionDep, user_in: UserUpdateMe, current_user: CurrentUser
|
*, session: SessionDep, user_in: UserUpdateMe, current_user: CurrentUser
|
||||||
) -> Any:
|
) -> Any:
|
||||||
@@ -114,7 +116,7 @@ def update_password_me(
|
|||||||
return Message(message="Password updated successfully")
|
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:
|
def read_user_me(current_user: CurrentUser) -> Any:
|
||||||
"""
|
"""
|
||||||
Get current user.
|
Get current user.
|
||||||
@@ -122,7 +124,7 @@ def read_user_me(current_user: CurrentUser) -> Any:
|
|||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
|
|
||||||
@router.post("/signup", response_model=UserOut)
|
@router.post("/signup", response_model=UserPublic)
|
||||||
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
|
def register_user(session: SessionDep, user_in: UserRegister) -> Any:
|
||||||
"""
|
"""
|
||||||
Create new user without the need to be logged in.
|
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
|
return user
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{user_id}", response_model=UserOut)
|
@router.get("/{user_id}", response_model=UserPublic)
|
||||||
def read_user_by_id(
|
def read_user_by_id(
|
||||||
user_id: int, session: SessionDep, current_user: CurrentUser
|
user_id: int, session: SessionDep, current_user: CurrentUser
|
||||||
) -> Any:
|
) -> Any:
|
||||||
@@ -164,7 +166,7 @@ def read_user_by_id(
|
|||||||
@router.patch(
|
@router.patch(
|
||||||
"/{user_id}",
|
"/{user_id}",
|
||||||
dependencies=[Depends(get_current_active_superuser)],
|
dependencies=[Depends(get_current_active_superuser)],
|
||||||
response_model=UserOut,
|
response_model=UserPublic,
|
||||||
)
|
)
|
||||||
def update_user(
|
def update_user(
|
||||||
*,
|
*,
|
||||||
|
@@ -48,12 +48,12 @@ class User(UserBase, table=True):
|
|||||||
|
|
||||||
|
|
||||||
# Properties to return via API, id is always required
|
# Properties to return via API, id is always required
|
||||||
class UserOut(UserBase):
|
class UserPublic(UserBase):
|
||||||
id: int
|
id: int
|
||||||
|
|
||||||
|
|
||||||
class UsersOut(SQLModel):
|
class UsersPublic(SQLModel):
|
||||||
data: list[UserOut]
|
data: list[UserPublic]
|
||||||
count: int
|
count: int
|
||||||
|
|
||||||
|
|
||||||
@@ -82,13 +82,13 @@ class Item(ItemBase, table=True):
|
|||||||
|
|
||||||
|
|
||||||
# Properties to return via API, id is always required
|
# Properties to return via API, id is always required
|
||||||
class ItemOut(ItemBase):
|
class ItemPublic(ItemBase):
|
||||||
id: int
|
id: int
|
||||||
owner_id: int
|
owner_id: int
|
||||||
|
|
||||||
|
|
||||||
class ItemsOut(SQLModel):
|
class ItemsPublic(SQLModel):
|
||||||
data: list[ItemOut]
|
data: list[ItemPublic]
|
||||||
count: int
|
count: int
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user