Skip to content

Commit

Permalink
fix(get): Fix miscalculated total_page on get_all_x requests
Browse files Browse the repository at this point in the history
  • Loading branch information
flo-ride committed Jan 25, 2025
1 parent a619a5d commit da62f13
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/src/location/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub async fn get_all_locations(
service::Query::list_locations_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_locations_with_condition(&conn, filter).await? / per_page) + 1;
let total_locations = service::Query::count_locations_with_condition(&conn, filter).await?;
let total_page = ((total_locations - 1) / per_page) + 1;

let locations = result.into_iter().map(Into::into).collect();
Ok(Json(LocationListResponse {
Expand Down
4 changes: 2 additions & 2 deletions api/src/product/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub async fn get_all_products(
service::Query::list_products_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_products_with_condition(&conn, filter).await? / per_page) + 1;
let total_products = service::Query::count_products_with_condition(&conn, filter).await?;
let total_page = ((total_products.max(1) - 1) / per_page) + 1;

let products = result
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions api/src/recipe/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub async fn get_all_recipes(
service::Query::list_recipes_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_recipes_with_condition(&conn, filter).await? / per_page) + 1;
let total_recipes = service::Query::count_recipes_with_condition(&conn, filter).await?;
let total_page = ((total_recipes.max(1) - 1) / per_page) + 1;

let recipes = result
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions api/src/refill/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub async fn get_all_refills(
service::Query::list_refills_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_refills_with_condition(&conn, filter).await? / per_page) + 1;
let total_refills = service::Query::count_refills_with_condition(&conn, filter).await?;
let total_page = ((total_refills.max(1) - 1) / per_page) + 1;

let refills: Result<Vec<_>, RefillResponseError> =
result.into_iter().map(TryInto::try_into).collect();
Expand Down
4 changes: 2 additions & 2 deletions api/src/user/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ pub async fn get_all_users(
service::Query::list_users_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_users_with_condition(&conn, filter).await? / per_page) + 1;
let total_users = service::Query::count_users_with_condition(&conn, filter).await?;
let total_page = ((total_users.max(1) - 1) / per_page) + 1;

let users = result.into_iter().map(|x| x.into()).collect();
Ok(Json(UserListResponse {
Expand Down
4 changes: 2 additions & 2 deletions api/src/warehouse/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub async fn get_all_warehouses(
service::Query::list_warehouses_with_condition(&conn, filter.clone(), sort, page, per_page)
.await?;

let total_page =
(service::Query::count_warehouses_with_condition(&conn, filter).await? / per_page) + 1;
let total_warehouses = service::Query::count_warehouses_with_condition(&conn, filter).await?;
let total_page = ((total_warehouses.max(1) - 1) / per_page) + 1;

let warehouses = result.into_iter().map(Into::into).collect();
Ok(Json(WarehouseListResponse {
Expand Down

0 comments on commit da62f13

Please sign in to comment.