diff --git a/docs-site/content/docs/the-app/controller.md b/docs-site/content/docs/the-app/controller.md index 7c424d7be..bbd32272d 100644 --- a/docs-site/content/docs/the-app/controller.md +++ b/docs-site/content/docs/the-app/controller.md @@ -917,6 +917,7 @@ impl PaginationResponse { page: pagination_query.page, page_size: pagination_query.page_size, total_pages: data.total_pages, + total_items: data.total_items, }, } } diff --git a/src/controller/views/pagination.rs b/src/controller/views/pagination.rs index 09d53f966..8fb31fcf2 100644 --- a/src/controller/views/pagination.rs +++ b/src/controller/views/pagination.rs @@ -17,6 +17,8 @@ pub struct PagerMeta { pub page_size: u64, #[serde(rename(serialize = "total_pages"))] pub total_pages: u64, + #[serde(rename(serialize = "total_items"))] + pub total_items: u64, } impl Pager { diff --git a/src/model/query/paginate/mod.rs b/src/model/query/paginate/mod.rs index 04ef388b9..af2a19a9b 100644 --- a/src/model/query/paginate/mod.rs +++ b/src/model/query/paginate/mod.rs @@ -78,6 +78,7 @@ where pub struct PageResponse { pub page: Vec, pub total_pages: u64, + pub total_items: u64, } use crate::Result as LocoResult; @@ -163,10 +164,14 @@ where }; let query = entity.paginate(db, pagination_query.page_size); - let total_pages = query.num_pages().await?; + let total_pages_and_items = query.num_items_and_pages().await?; let page: Vec<::Model> = query.fetch_page(page).await?; - let paginated_response = PageResponse { page, total_pages }; + let paginated_response = PageResponse { + page, + total_pages: total_pages_and_items.number_of_pages, + total_items: total_pages_and_items.number_of_items, + }; Ok(paginated_response) } @@ -211,8 +216,12 @@ where }; let query = selector.paginate(db, pagination_query.page_size); - let total_pages = query.num_pages().await?; + let total_pages_and_items = query.num_items_and_pages().await?; let page = query.fetch_page(page).await?; - Ok(PageResponse { page, total_pages }) + Ok(PageResponse { + page, + total_pages: total_pages_and_items.number_of_pages, + total_items: total_pages_and_items.number_of_items, + }) }