Files
thoughts/thoughts-backend/models/src/queries/pagination.rs
Gabriel Kaszewski d92c9a747e
All checks were successful
Build and Deploy Thoughts / build-and-deploy-local (push) Successful in 2m30s
feat: implement pagination for user retrieval and update feed fetching logic
2025-09-09 02:53:24 +02:00

28 lines
620 B
Rust

use serde::Deserialize;
use utoipa::IntoParams;
const DEFAULT_PAGE: u64 = 1;
const DEFAULT_PAGE_SIZE: u64 = 20;
#[derive(Deserialize, IntoParams)]
pub struct PaginationQuery {
#[param(nullable = true, example = 1)]
page: Option<u64>,
#[param(nullable = true, example = 20)]
page_size: Option<u64>,
}
impl PaginationQuery {
pub fn page(&self) -> u64 {
self.page.unwrap_or(DEFAULT_PAGE).max(1)
}
pub fn page_size(&self) -> u64 {
self.page_size.unwrap_or(DEFAULT_PAGE_SIZE).max(1)
}
pub fn offset(&self) -> u64 {
(self.page() - 1) * self.page_size()
}
}