refactor(api): share Pagination across admin/public; cover get-by-id auth
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//! 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user