Skip to content
Closed
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
13 changes: 10 additions & 3 deletions backend/app/api/routes/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
from sqlmodel import col, func, select

from app.api.deps import CurrentUser, SessionDep
from app.models import Item, ItemCreate, ItemPublic, ItemsPublic, ItemUpdate, Message
from app.models import (
Item,
ItemCreate,
ItemPublic,
ItemUpdate,
Message,
PaginatedResponse,
)

router = APIRouter(prefix="/items", tags=["items"])


@router.get("/", response_model=ItemsPublic)
@router.get("/", response_model=PaginatedResponse[ItemPublic])
def read_items(
session: SessionDep, current_user: CurrentUser, skip: int = 0, limit: int = 100
) -> Any:
Expand Down Expand Up @@ -42,7 +49,7 @@ def read_items(
items = session.exec(statement).all()

items_public = [ItemPublic.model_validate(item) for item in items]
return ItemsPublic(data=items_public, count=count)
return PaginatedResponse(data=items_public, count=count)


@router.get("/{id}", response_model=ItemPublic)
Expand Down
6 changes: 3 additions & 3 deletions backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from app.models import (
Item,
Message,
PaginatedResponse,
UpdatePassword,
User,
UserCreate,
UserPublic,
UserRegister,
UsersPublic,
UserUpdate,
UserUpdateMe,
)
Expand All @@ -32,7 +32,7 @@
@router.get(
"/",
dependencies=[Depends(get_current_active_superuser)],
response_model=UsersPublic,
response_model=PaginatedResponse[UserPublic],
)
def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
"""
Expand All @@ -48,7 +48,7 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
users = session.exec(statement).all()

users_public = [UserPublic.model_validate(user) for user in users]
return UsersPublic(data=users_public, count=count)
return PaginatedResponse(data=users_public, count=count)


@router.post(
Expand Down
19 changes: 9 additions & 10 deletions backend/app/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
from datetime import UTC, datetime
from typing import Generic, TypeVar

from pydantic import EmailStr
from sqlalchemy import DateTime
Expand All @@ -10,6 +11,14 @@ def get_datetime_utc() -> datetime:
return datetime.now(UTC)


T = TypeVar("T")


class PaginatedResponse(SQLModel, Generic[T]):
data: list[T]
count: int


# Shared properties
class UserBase(SQLModel):
email: EmailStr = Field(unique=True, index=True, max_length=255)
Expand Down Expand Up @@ -65,11 +74,6 @@ class UserPublic(UserBase):
created_at: datetime | None = None


class UsersPublic(SQLModel):
data: list[UserPublic]
count: int


# Shared properties
class ItemBase(SQLModel):
title: str = Field(min_length=1, max_length=255)
Expand Down Expand Up @@ -107,11 +111,6 @@ class ItemPublic(ItemBase):
created_at: datetime | None = None


class ItemsPublic(SQLModel):
data: list[ItemPublic]
count: int


# Generic message
class Message(SQLModel):
message: str
Expand Down
72 changes: 34 additions & 38 deletions frontend/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,6 @@ export const ItemUpdateSchema = {
title: 'ItemUpdate'
} as const;

export const ItemsPublicSchema = {
properties: {
data: {
items: {
'$ref': '#/components/schemas/ItemPublic'
},
type: 'array',
title: 'Data'
},
count: {
type: 'integer',
title: 'Count'
}
},
type: 'object',
required: ['data', 'count'],
title: 'ItemsPublic'
} as const;

export const MessageSchema = {
properties: {
message: {
Expand Down Expand Up @@ -226,6 +207,40 @@ export const NewPasswordSchema = {
title: 'NewPassword'
} as const;

export const PaginatedResponse_ItemPublic_Schema = {
properties: {
data: {
items: {},
type: 'array',
title: 'Data'
},
count: {
type: 'integer',
title: 'Count'
}
},
type: 'object',
required: ['data', 'count'],
title: 'PaginatedResponse[ItemPublic]'
} as const;

export const PaginatedResponse_UserPublic_Schema = {
properties: {
data: {
items: {},
type: 'array',
title: 'Data'
},
count: {
type: 'integer',
title: 'Count'
}
},
type: 'object',
required: ['data', 'count'],
title: 'PaginatedResponse[UserPublic]'
} as const;

export const PrivateUserCreateSchema = {
properties: {
email: {
Expand Down Expand Up @@ -514,25 +529,6 @@ export const UserUpdateMeSchema = {
title: 'UserUpdateMe'
} as const;

export const UsersPublicSchema = {
properties: {
data: {
items: {
'$ref': '#/components/schemas/UserPublic'
},
type: 'array',
title: 'Data'
},
count: {
type: 'integer',
title: 'Count'
}
},
type: 'object',
required: ['data', 'count'],
title: 'UsersPublic'
} as const;

export const ValidationErrorSchema = {
properties: {
loc: {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/client/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ItemsService {
* @param data The data for the request.
* @param data.skip
* @param data.limit
* @returns ItemsPublic Successful Response
* @returns PaginatedResponse_ItemPublic_ Successful Response
* @throws ApiError
*/
public static readItems(data: ItemsReadItemsData = {}): CancelablePromise<ItemsReadItemsResponse> {
Expand Down Expand Up @@ -242,7 +242,7 @@ export class UsersService {
* @param data The data for the request.
* @param data.skip
* @param data.limit
* @returns UsersPublic Successful Response
* @returns PaginatedResponse_UserPublic_ Successful Response
* @throws ApiError
*/
public static readUsers(data: UsersReadUsersData = {}): CancelablePromise<UsersReadUsersResponse> {
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export type ItemPublic = {
created_at?: (string | null);
};

export type ItemsPublic = {
data: Array<ItemPublic>;
count: number;
};

export type ItemUpdate = {
title?: (string | null);
description?: (string | null);
Expand All @@ -45,6 +40,16 @@ export type NewPassword = {
new_password: string;
};

export type PaginatedResponse_ItemPublic_ = {
data: Array<unknown>;
count: number;
};

export type PaginatedResponse_UserPublic_ = {
data: Array<unknown>;
count: number;
};

export type PrivateUserCreate = {
email: string;
password: string;
Expand Down Expand Up @@ -85,11 +90,6 @@ export type UserRegister = {
full_name?: (string | null);
};

export type UsersPublic = {
data: Array<UserPublic>;
count: number;
};

export type UserUpdate = {
email?: (string | null);
is_active?: (boolean | null);
Expand Down Expand Up @@ -118,7 +118,7 @@ export type ItemsReadItemsData = {
skip?: number;
};

export type ItemsReadItemsResponse = (ItemsPublic);
export type ItemsReadItemsResponse = (PaginatedResponse_ItemPublic_);

export type ItemsCreateItemData = {
requestBody: ItemCreate;
Expand Down Expand Up @@ -182,7 +182,7 @@ export type UsersReadUsersData = {
skip?: number;
};

export type UsersReadUsersResponse = (UsersPublic);
export type UsersReadUsersResponse = (PaginatedResponse_UserPublic_);

export type UsersCreateUserData = {
requestBody: UserCreate;
Expand Down
Loading