Files
desi_explorer/api/src/routes/catalogs.rs
T
sam_oneal 1443369f6c
CI / Detect changed paths (pull_request) Failing after 33m59s
CI / Infra unit tests, vet, and preview (pull_request) Has been skipped
CI / API unit tests and lint (pull_request) Failing after 31m0s
CI / Odin unit tests and build (pull_request) Failing after 31m9s
add dev resources; plumb GUI_ENV_FILE/API_ENV_FILE/API_DESI_DATA into run targets
2026-09-07 14:55:49 -06:00

49 lines
1.1 KiB
Rust

use std::sync::Arc;
use axum::{
extract::{Query, State},
Json,
};
use serde::Deserialize;
use crate::models::{Catalog, CatalogObject};
use crate::store::CatalogStore;
pub async fn list_catalogs(State(state): State<Arc<CatalogStore>>) -> Json<Vec<Catalog>> {
Json(state.catalogs.clone())
}
#[derive(Debug, Deserialize)]
pub struct ObjectQuery {
catalog: Option<String>,
#[serde(default)]
limit: Option<usize>,
}
pub async fn list_objects(
State(state): State<Arc<CatalogStore>>,
Query(query): Query<ObjectQuery>,
) -> Json<Vec<CatalogObject>> {
let limit = query.limit.unwrap_or(100).min(10_000);
tracing::debug!(
%limit,
catalog = query.catalog.as_deref().unwrap_or("all"),
objects = state.objects.len(),
"querying catalog objects"
);
let objects: Vec<CatalogObject> = match &query.catalog {
Some(catalog) => state
.objects
.iter()
.filter(|o| &o.catalog == catalog)
.take(limit)
.cloned()
.collect(),
None => state.objects.iter().take(limit).cloned().collect(),
};
Json(objects)
}