|
1 | 1 | import inspect |
2 | 2 | import logging |
| 3 | +import math |
3 | 4 | from datetime import datetime, timezone |
4 | 5 | from typing import Annotated, Any |
5 | 6 |
|
@@ -574,6 +575,27 @@ def get_users(db_session: Annotated[Session, Depends(get_db_session)], |
574 | 575 | return [BiocommonsUserResponse.from_db_user(user) for user in users] |
575 | 576 |
|
576 | 577 |
|
| 578 | +class UsersPageInfoResponse(BaseModel): |
| 579 | + total: int |
| 580 | + pages: int |
| 581 | + per_page: int |
| 582 | + |
| 583 | + |
| 584 | +@router.get("/users/pages", |
| 585 | + response_model=UsersPageInfoResponse,) |
| 586 | +def get_users_page_info(db_session: Annotated[Session, Depends(get_db_session)], |
| 587 | + query_params: Annotated[UserQueryParams, Depends()], |
| 588 | + admin_user: Annotated[SessionUser, Depends(get_session_user)], |
| 589 | + pagination: Annotated[PaginationParams, Depends(get_pagination_params)]): |
| 590 | + """ |
| 591 | + Return the total number of users and number of pages matching the query parameters and |
| 592 | + current admin roles (useful for pagination). |
| 593 | + """ |
| 594 | + admin_roles = admin_user.access_token.biocommons_roles |
| 595 | + query_params.check_missing_ids(db_session) |
| 596 | + total = query_params.get_count(db_session=db_session, admin_roles=admin_roles) |
| 597 | + return UsersPageInfoResponse(total=total, pages=math.ceil(total / pagination.per_page), per_page=pagination.per_page) |
| 598 | + |
577 | 599 | @router.get( |
578 | 600 | "/users/counts", |
579 | 601 | response_model=UserCountsResponse, |
|
0 commit comments