about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/routes/datasets.rs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/routes/datasets.rs b/src/routes/datasets.rs
index 1835b4c..eed7d1c 100644
--- a/src/routes/datasets.rs
+++ b/src/routes/datasets.rs
@@ -107,7 +107,8 @@ fn get_dataset_probesets_result(
 #[utoipa::path(get, path = "/datasets/{dataset}/probesets", summary = "List the expression (ProbeSet) traits belonging to a dataset", params(
     ("dataset" = String, Path, description = "Dataset Name, Name2, FullName, ShortName or numeric Id")
 ), responses(
-    (status = 200, description = "The probesets' ProbeSetXRef/ProbeSet metadata", body = Envelope<Vec<db::ProbeSetInfo>>),
+    (status = 200, description = "The probesets' ProbeSetXRef/ProbeSet metadata; \
+`ids_only`/`names_only` answer one value per probeset instead", body = Envelope<crate::listing::Rows>),
     Unauthorized,
     (status = 403, description = "The dataset isn't public, and the caller isn't authorized for it", body = ApiError),
     (status = 404, description = "No matching dataset", body = ApiError),
@@ -118,8 +119,20 @@ pub async fn dataset_probesets(
     ctx: Ctx,
     Path(dataset): Path<String>,
     token: AuthToken,
-) -> Result<Json<Envelope<Vec<db::ProbeSetInfo>>>, ApiError> {
+    axum::extract::Query(params): axum::extract::Query<crate::listing::ListingParams>,
+) -> Result<Json<Envelope<crate::listing::Rows>>, ApiError> {
     let rid = ctx.request_info();
+    // No listing parameters means the old answer: `Rows::Objects`.
+    let listing = crate::listing::Listing::parse(&params).map_err(|detail| {
+        ApiError::new(
+            StatusCode::UNPROCESSABLE_ENTITY,
+            "invalid_listing",
+            "Invalid listing parameters",
+            detail,
+            "dataset_probesets",
+        )
+        .with_request_id(rid.clone())
+    })?;
     let not_found_name = dataset.clone();
     let auth_server_url = Config::load().auth_server_url.clone();
     tokio::task::spawn_blocking(move || {
@@ -150,8 +163,14 @@ pub async fn dataset_probesets(
         .with_request_id(rid.clone()),
     })
     .and_then(|lookup| match lookup {
-        DatasetProbesetsLookup::Found(_authorized, probesets) => Ok(Json(
-            ctx.envelope(probesets)
+        DatasetProbesetsLookup::Found(_authorized, probesets) => {
+            let rows: Vec<serde_json::Value> = probesets
+                .iter()
+                .map(|probeset| serde_json::to_value(probeset).unwrap_or(serde_json::Value::Null))
+                .collect();
+            let (shaped, missing) = listing.shape(rows, params.limit_to.as_deref());
+            let mut envelope = ctx
+                .envelope(shaped)
                 .with_note(db::LOD_NOTE)
                 .with_next(
                     &format!("/datasets/{}", path_segment(&not_found_name)),
@@ -161,8 +180,16 @@ pub async fn dataset_probesets(
                     &format!("/datasets/{}/probesets/{{probeset}}/values", path_segment(&not_found_name)),
                     "One probeset's value per strain, with the mapping suggestions",
                 )
-                .with_links(crate::suggest::root_links()),
-        )),
+                .with_links(crate::suggest::root_links());
+            if !missing.is_empty() {
+                envelope = envelope.with_note(&format!(
+                    "limit_to named {} value(s) that matched no probeset: {}",
+                    missing.len(),
+                    missing.join(", ")
+                ));
+            }
+            Ok(Json(envelope))
+        }
         DatasetProbesetsLookup::Forbidden => Err(ApiError::new(
             StatusCode::FORBIDDEN,
             "forbidden",