diff --git a/editoast/src/views/light_rolling_stocks.rs b/editoast/src/views/light_rolling_stocks.rs index 69b94b3f8dd..c7c94f5b300 100644 --- a/editoast/src/views/light_rolling_stocks.rs +++ b/editoast/src/views/light_rolling_stocks.rs @@ -217,7 +217,7 @@ mod tests { use crate::error::InternalError; use crate::modelsv2::fixtures::create_fast_rolling_stock; use crate::modelsv2::fixtures::create_rolling_stock_livery_fixture; - use crate::views::pagination::PaginatedResponse; + use crate::views::light_rolling_stocks::LightRollingStockWithLiveriesCountList; use crate::views::test_app::TestAppBuilder; fn is_sorted(data: &[i64]) -> bool { @@ -313,12 +313,12 @@ mod tests { .collect::>(); let request = app.get("/light_rolling_stock/"); - let response: PaginatedResponse = + let response: LightRollingStockWithLiveriesCountList = app.fetch(request).assert_status(StatusCode::OK).json_into(); - let count = response.count; + let count = response.stats.count; let uri = format!("/light_rolling_stock/?page_size={count}"); let request = app.get(&uri); - let response: PaginatedResponse = + let response: LightRollingStockWithLiveriesCountList = app.fetch(request).assert_status(StatusCode::OK).json_into(); // Ensure that AT LEAST all the rolling stocks create above are returned, in order diff --git a/editoast/src/views/pagination.rs b/editoast/src/views/pagination.rs index a0c4de9e84f..685c06c278b 100644 --- a/editoast/src/views/pagination.rs +++ b/editoast/src/views/pagination.rs @@ -1,8 +1,3 @@ -use diesel::pg::Pg; -use diesel::query_builder::*; -use diesel::sql_types::BigInt; -use diesel::sql_types::Untyped; -use diesel::QueryResult; use editoast_derive::EditoastError; use serde::Deserialize; use serde::Serialize; @@ -127,45 +122,6 @@ pub trait PaginatedList: ListAndCount + 'static { impl PaginatedList for T where T: ListAndCount + 'static {} -/// Generates a specialized [PaginatedResponse], commented, annotated with `ToSchema` -/// -/// We need to specialize manually PaginatedResponse with each -/// type we intend to use it with, otherwise utoipa will generate a $ref to T... -#[macro_export] -macro_rules! decl_paginated_response { - ($name:ident, $item:ty) => { - $crate::decl_paginated_response! {pub(self) $name, $item} - }; - ($vis:vis $name:ident, $item:ty) => { - /// A paginated response - #[allow(unused)] - #[allow(clippy::needless_pub_self)] - #[derive(utoipa::ToSchema)] - $vis struct $name { - /// The total number of items - pub count: i64, - /// The previous page number - #[schema(required)] - pub previous: Option, - /// The next page number - #[schema(required)] - pub next: Option, - /// The list of results - #[schema(required)] - pub results: Vec<$item>, - } - }; -} - -/// A paginated response -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub struct PaginatedResponse { - pub count: i64, - pub previous: Option, - pub next: Option, - pub results: Vec, -} - #[derive(Debug, Clone, Copy, Deserialize, IntoParams)] #[into_params(parameter_in = Query)] pub struct PaginationQueryParam { @@ -235,32 +191,6 @@ pub enum PaginationError { }, } -#[derive(Debug, Clone, Copy, QueryId)] -pub struct Paginated { - query: T, - page_size: i64, - offset: i64, -} - -impl QueryFragment for Paginated -where - T: QueryFragment, -{ - fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> { - out.push_sql("SELECT *, COUNT(*) OVER () FROM ("); - self.query.walk_ast(out.reborrow())?; - out.push_sql(") as paged_query_with LIMIT "); - out.push_bind_param::(&self.page_size)?; - out.push_sql(" OFFSET "); - out.push_bind_param::(&self.offset)?; - Ok(()) - } -} - -impl Query for Paginated { - type SqlType = Untyped; -} - #[cfg(test)] mod pagination_stats_tests { use super::PaginationStats;