add query limit and skip
This commit is contained in:
parent
778e579424
commit
2dedf30095
@ -7,10 +7,16 @@ from typing import Annotated
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/users", tags=["users"], response_model=list[users.UserOut])
|
||||
async def read_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
||||
async def read_users(skip : int = 0, limit : int = 20, authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
||||
if limit < 1 or skip < 0:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="skip should be greater than 0 and limit should be greater than 1"
|
||||
)
|
||||
limit = limit + skip
|
||||
listUsers = []
|
||||
user_repository = users.UserRepository(database=database.database)
|
||||
for user_index in user_repository.find_by({}, limit=20, skip=0):
|
||||
for user_index in user_repository.find_by({}, limit=limit, skip=skip):
|
||||
user = users.UserOut(id=user_index.id, username=user_index.username, disabled=user_index.disabled, roles=user_index.roles)
|
||||
listUsers.append(user)
|
||||
return listUsers
|
||||
|
Loading…
x
Reference in New Issue
Block a user