jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
878 stars 143 forks source link

Query with sorting #38

Closed 8thgencore closed 1 year ago

8thgencore commented 1 year ago

Why don't you use the function get_multi_paginated_ordered when executing a query with sorting

@router.get(
    "/order_by_created_at",
    response_model=IGetResponsePaginated[IUserReadWithoutGroups],
)
async def get_hero_list_order_by_created_at(
    params: Params = Depends(),
    current_user: User = Depends(
        deps.get_current_user(required_roles=[IRoleEnum.admin, IRoleEnum.manager])
    ),
):
    """
    Gets a paginated list of users ordered by created datetime
    """
    query = select(User).order_by(User.created_at)
    users = await crud.user.get_multi_paginated(query=query, params=params)
    return create_response(data=users)
jonra1993 commented 1 year ago

Hello, @8thgencore thanks for reporting this issue. It has been solved on this commit 9791143c94cae9b67f8a40c8ec1b96341d5ad29b