Skip to content

♻️ Refactor rename ModelsOut to ModelsPublic #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/app/api/routes/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
UpdatePassword,
User,
UserCreate,
UserOut,
UserPublic,
UserRegister,
UsersOut,
UsersPublic,
UserUpdate,
UserUpdateMe,
)
Expand All @@ -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:
"""
Expand All @@ -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:
"""
Expand All @@ -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:
Expand Down Expand Up @@ -114,15 +116,15 @@ 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.
"""
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.
Expand All @@ -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:
Expand All @@ -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(
*,
Expand Down
12 changes: 6 additions & 6 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down