init domain

This commit is contained in:
2026-05-04 00:26:10 +02:00
commit 810bad1126
30 changed files with 3033 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
use crate::errors::DomainError;
#[derive(Clone, Debug)]
pub struct Paginated<T> {
pub items: Vec<T>,
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 = 20;
pub fn new(limit: Option<u32>, offset: Option<u32>) -> Result<Self, DomainError> {
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,
}
}
}