|
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; |
6 | 1 | use editoast_derive::EditoastError;
|
7 | 2 | use serde::Deserialize;
|
8 | 3 | use serde::Serialize;
|
@@ -127,45 +122,6 @@ pub trait PaginatedList: ListAndCount + 'static {
|
127 | 122 |
|
128 | 123 | impl<T> PaginatedList for T where T: ListAndCount + 'static {}
|
129 | 124 |
|
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 |
| - |
169 | 125 | #[derive(Debug, Clone, Copy, Deserialize, IntoParams)]
|
170 | 126 | #[into_params(parameter_in = Query)]
|
171 | 127 | pub struct PaginationQueryParam {
|
@@ -235,32 +191,6 @@ pub enum PaginationError {
|
235 | 191 | },
|
236 | 192 | }
|
237 | 193 |
|
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 |
| - |
264 | 194 | #[cfg(test)]
|
265 | 195 | mod pagination_stats_tests {
|
266 | 196 | use super::PaginationStats;
|
|
0 commit comments