1888e185f7
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
600 B
Rust
24 lines
600 B
Rust
//! Shared pagination query parameters used by both admin and public handlers.
|
|
|
|
use serde::Deserialize;
|
|
|
|
pub(crate) const DEFAULT_LIMIT: i64 = 50;
|
|
pub(crate) const MAX_LIMIT: i64 = 200;
|
|
|
|
/// Pagination query parameters with sane defaults and a hard cap.
|
|
#[derive(Deserialize)]
|
|
pub(crate) struct Pagination {
|
|
pub(crate) limit: Option<i64>,
|
|
pub(crate) offset: Option<i64>,
|
|
}
|
|
|
|
impl Pagination {
|
|
pub(crate) fn limit(&self) -> i64 {
|
|
self.limit.unwrap_or(DEFAULT_LIMIT).clamp(1, MAX_LIMIT)
|
|
}
|
|
|
|
pub(crate) fn offset(&self) -> i64 {
|
|
self.offset.unwrap_or(0).max(0)
|
|
}
|
|
}
|