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:
2026-06-02 21:53:21 +02:00
parent 0055616099
commit 1888e185f7
5 changed files with 40 additions and 43 deletions
+2 -22
View File
@@ -14,10 +14,10 @@ use axum::{
routing::get,
};
use domain::{CatalogueObject, ObjectId};
use serde::{Deserialize, Serialize};
use serde::Serialize;
use utoipa::ToSchema;
use crate::AppState;
use crate::{AppState, pagination::Pagination};
/// A catalogue object as exposed on the public surface (public-safe fields only).
#[derive(Serialize, ToSchema)]
@@ -50,26 +50,6 @@ pub(crate) struct PublicObjectPage {
pub offset: i64,
}
/// Pagination query parameters with sane defaults and a hard cap.
#[derive(Deserialize)]
pub(crate) struct Pagination {
limit: Option<i64>,
offset: Option<i64>,
}
const DEFAULT_LIMIT: i64 = 50;
const MAX_LIMIT: i64 = 200;
impl Pagination {
fn limit(&self) -> i64 {
self.limit.unwrap_or(DEFAULT_LIMIT).clamp(1, MAX_LIMIT)
}
fn offset(&self) -> i64 {
self.offset.unwrap_or(0).max(0)
}
}
/// List public objects (paginated).
#[utoipa::path(
get,