♻️ 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 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:
|
||||
|
@@ -10,7 +10,7 @@ from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser
|
||||
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
|
||||
|
@@ -17,9 +17,9 @@ from app.models import (
|
||||
UpdatePassword,
|
||||
User,
|
||||
UserCreate,
|
||||
UserOut,
|
||||
UserPublic,
|
||||
UserRegister,
|
||||
UsersOut,
|
||||
UsersPublic,
|
||||
UserUpdate,
|
||||
UserUpdateMe,
|
||||
)
|
||||
@@ -29,7 +29,9 @@ router = APIRouter()
|
||||
|
||||
|
||||
@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(
|
||||
*,
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user