use crate::errors::DomainError; #[derive(Clone, Debug)] pub struct Paginated { pub items: Vec, pub total_count: u64, pub limit: u32, pub offset: u32, } #[derive(Clone, Debug)] pub struct PageParams { pub limit: u32, pub offset: u32, } impl PageParams { const MAX_LIMIT: u32 = 100; const DEFAULT_LIMIT: u32 = 5; pub fn new(limit: Option, offset: Option) -> Result { let l = limit.unwrap_or(Self::DEFAULT_LIMIT); if l == 0 || l > Self::MAX_LIMIT { return Err(DomainError::ValidationError(format!( "Limit must be between 1 and {}", Self::MAX_LIMIT ))); } Ok(Self { limit: l, offset: offset.unwrap_or(0), }) } } impl Default for PageParams { fn default() -> Self { Self { limit: Self::DEFAULT_LIMIT, offset: 0, } } }