diff --git a/src/compositions/betting/composition.rs b/src/compositions/betting/composition.rs index a7f5702..791b9db 100644 --- a/src/compositions/betting/composition.rs +++ b/src/compositions/betting/composition.rs @@ -128,6 +128,25 @@ impl Composition { } } + fn get_pagination(&self, find_all: &models::FindAll) -> Result { + 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 { 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);