Fixed pages metadata

This commit is contained in:
Benjamin Sherriff
2023-10-04 11:07:28 -04:00
parent 23d42953f0
commit 4d3e8ae981
3 changed files with 8 additions and 3 deletions

View File

@@ -50,7 +50,10 @@ impl QuerySpell {
pub fn get_all(filters: &QueryFilters, limit: i32, page: i32) -> Result<Vec<Self>, ServiceError> {
let mut conn = crate::db::connection()?;
let mut query = spells::table.limit(limit as i64).into_boxed();
query = query.filter(spells::id.gt(std::cmp::max(0, page - 1) * limit));
// Limit query to page and limit
let offset = (page - 1) * limit;
query = query.offset(offset as i64);
// Apply filters
if let Some(name) = filters.by_name.to_owned() {
query = query.filter(spells::name.ilike(format!("%{}%", name)));
}