Skip to content

Commit 43a9891

Browse files
committed
editoast: remove old pagination system
1 parent 987553e commit 43a9891

File tree

2 files changed

+4
-74
lines changed

2 files changed

+4
-74
lines changed

editoast/src/views/light_rolling_stocks.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mod tests {
217217
use crate::error::InternalError;
218218
use crate::modelsv2::fixtures::create_fast_rolling_stock;
219219
use crate::modelsv2::fixtures::create_rolling_stock_livery_fixture;
220-
use crate::views::pagination::PaginatedResponse;
220+
use crate::views::light_rolling_stocks::LightRollingStockWithLiveriesCountList;
221221
use crate::views::test_app::TestAppBuilder;
222222

223223
fn is_sorted(data: &[i64]) -> bool {
@@ -313,12 +313,12 @@ mod tests {
313313
.collect::<HashSet<_>>();
314314

315315
let request = app.get("/light_rolling_stock/");
316-
let response: PaginatedResponse<LightRollingStockWithLiveries> =
316+
let response: LightRollingStockWithLiveriesCountList =
317317
app.fetch(request).assert_status(StatusCode::OK).json_into();
318-
let count = response.count;
318+
let count = response.stats.count;
319319
let uri = format!("/light_rolling_stock/?page_size={count}");
320320
let request = app.get(&uri);
321-
let response: PaginatedResponse<LightRollingStockWithLiveries> =
321+
let response: LightRollingStockWithLiveriesCountList =
322322
app.fetch(request).assert_status(StatusCode::OK).json_into();
323323

324324
// Ensure that AT LEAST all the rolling stocks create above are returned, in order

editoast/src/views/pagination.rs

-70
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
use diesel::pg::Pg;
2-
use diesel::query_builder::*;
3-
use diesel::sql_types::BigInt;
4-
use diesel::sql_types::Untyped;
5-
use diesel::QueryResult;
61
use editoast_derive::EditoastError;
72
use serde::Deserialize;
83
use serde::Serialize;
@@ -127,45 +122,6 @@ pub trait PaginatedList: ListAndCount + 'static {
127122

128123
impl<T> PaginatedList for T where T: ListAndCount + 'static {}
129124

130-
/// Generates a specialized [PaginatedResponse], commented, annotated with `ToSchema`
131-
///
132-
/// We need to specialize manually PaginatedResponse with each
133-
/// type we intend to use it with, otherwise utoipa will generate a $ref to T...
134-
#[macro_export]
135-
macro_rules! decl_paginated_response {
136-
($name:ident, $item:ty) => {
137-
$crate::decl_paginated_response! {pub(self) $name, $item}
138-
};
139-
($vis:vis $name:ident, $item:ty) => {
140-
/// A paginated response
141-
#[allow(unused)]
142-
#[allow(clippy::needless_pub_self)]
143-
#[derive(utoipa::ToSchema)]
144-
$vis struct $name {
145-
/// The total number of items
146-
pub count: i64,
147-
/// The previous page number
148-
#[schema(required)]
149-
pub previous: Option<i64>,
150-
/// The next page number
151-
#[schema(required)]
152-
pub next: Option<i64>,
153-
/// The list of results
154-
#[schema(required)]
155-
pub results: Vec<$item>,
156-
}
157-
};
158-
}
159-
160-
/// A paginated response
161-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
162-
pub struct PaginatedResponse<T> {
163-
pub count: i64,
164-
pub previous: Option<i64>,
165-
pub next: Option<i64>,
166-
pub results: Vec<T>,
167-
}
168-
169125
#[derive(Debug, Clone, Copy, Deserialize, IntoParams)]
170126
#[into_params(parameter_in = Query)]
171127
pub struct PaginationQueryParam {
@@ -235,32 +191,6 @@ pub enum PaginationError {
235191
},
236192
}
237193

238-
#[derive(Debug, Clone, Copy, QueryId)]
239-
pub struct Paginated<T> {
240-
query: T,
241-
page_size: i64,
242-
offset: i64,
243-
}
244-
245-
impl<T> QueryFragment<Pg> for Paginated<T>
246-
where
247-
T: QueryFragment<Pg>,
248-
{
249-
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
250-
out.push_sql("SELECT *, COUNT(*) OVER () FROM (");
251-
self.query.walk_ast(out.reborrow())?;
252-
out.push_sql(") as paged_query_with LIMIT ");
253-
out.push_bind_param::<BigInt, _>(&self.page_size)?;
254-
out.push_sql(" OFFSET ");
255-
out.push_bind_param::<BigInt, _>(&self.offset)?;
256-
Ok(())
257-
}
258-
}
259-
260-
impl<T: Query> Query for Paginated<T> {
261-
type SqlType = Untyped;
262-
}
263-
264194
#[cfg(test)]
265195
mod pagination_stats_tests {
266196
use super::PaginationStats;

0 commit comments

Comments
 (0)