pagination is added
This commit is contained in:
parent
20c4490eec
commit
67ee99ab60
|
@ -128,6 +128,25 @@ impl Composition {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_pagination(&self, find_all: &models::FindAll) -> Result<String, Error> {
|
||||
let mut query_pagination = String::new();
|
||||
|
||||
if let Some(pagination) = &find_all.pagination {
|
||||
let page = pagination.page.unwrap_or(1);
|
||||
if let Some(page_size) = pagination.page_size {
|
||||
write!(
|
||||
&mut query_pagination,
|
||||
" OFFSET {} LIMIT {} ",
|
||||
((page - 1) * page_size) as i64,
|
||||
page_size as i64
|
||||
)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(query_pagination)
|
||||
}
|
||||
|
||||
fn get_ordery_by(&self, find_all: &models::FindAll) -> Result<String, Error> {
|
||||
let mut query_ordery_by = String::new();
|
||||
|
||||
|
@ -503,6 +522,11 @@ impl Composition {
|
|||
write!(&mut query, " ORDER BY {}", query_ordery_by)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
let query_pagination = self.get_pagination(find_all)?;
|
||||
if !query_pagination.is_empty() {
|
||||
write!(&mut query, " {} ", query_pagination)
|
||||
.map_err(|e| diesel::result::Error::QueryBuilderError(e.to_string().into()))?;
|
||||
}
|
||||
|
||||
println!("query: {}", query);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user