Fixed pages metadata
This commit is contained in:
@@ -67,5 +67,6 @@ pub struct GetResponse<T> {
|
||||
pub struct Metadata {
|
||||
pub total: i32,
|
||||
pub limit: i32,
|
||||
pub page: i32
|
||||
pub page: i32,
|
||||
pub pages: i32
|
||||
}
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
|
||||
metadata: Some(Metadata {
|
||||
total: total_count as i32,
|
||||
limit,
|
||||
page
|
||||
page,
|
||||
pages: max_page
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user