From 5419674c1f6635f31095b95ff4c1d5ca0e4fbcdc Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Tue, 17 Nov 2026 12:15:56 +0000 Subject: groups/{group}/datasets: limit_to / ids_only / names_only, old shape by default Third of the six. This one had no query struct at all, so it reuses crate::listing::ListingParams directly (now IntoParams, so it documents itself) instead of growing a per-handler copy. Verified on the deployed build: GET /groups/BXD/datasets objects, keys as before GET ...?names_only=true&limit_to=HC_M2_0606_P,NOPE ["HC_M2_0606_P"] + note: nope Read tier: 24 ok, 0 failed. --- src/listing.rs | 4 ++-- src/routes/groups.rs | 31 ++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/listing.rs b/src/listing.rs index 1e659ab..584429f 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -47,8 +47,8 @@ pub enum Rows { Plain(Vec), } -/// Query parameters three listings share. -#[derive(Debug, Clone, Default, Deserialize)] +/// Query parameters every listing shares, for handlers with no other parameters. +#[derive(Debug, Clone, Default, Deserialize, utoipa::IntoParams)] pub struct ListingParams { /// Keep only these ids or names, comma-separated. #[serde(default)] diff --git a/src/routes/groups.rs b/src/routes/groups.rs index 44fd605..727013a 100644 --- a/src/routes/groups.rs +++ b/src/routes/groups.rs @@ -1140,7 +1140,8 @@ pub async fn group_trait_case_attribute( #[utoipa::path(get, path = "/groups/{group}/datasets", summary = "List the expression (ProbeSet) datasets belonging to a group", params( ("group" = String, Path, description = "Group InbredSetName, Name, FullName or numeric Id") ), responses( - (status = 200, description = "The expression (ProbeSet) datasets belonging to the group", body = Envelope>), + (status = 200, description = "The expression (ProbeSet) datasets belonging to the group; \ +`ids_only`/`names_only` answer one value per dataset instead", body = Envelope), Unauthorized, (status = 404, description = "No matching group", body = ApiError), (status = 500, description = "Database error", body = ApiError) @@ -1150,8 +1151,20 @@ pub async fn group_datasets( ctx: Ctx, Path(group): Path, _token: AuthToken, -) -> Result>>, ApiError> { + Query(params): Query, +) -> Result>, ApiError> { let rid = ctx.request_info(); + // No listing parameters means the old answer: `Rows::Objects`. + let listing = crate::listing::Listing::parse(¶ms).map_err(|detail| { + ApiError::new( + StatusCode::UNPROCESSABLE_ENTITY, + "invalid_listing", + "Invalid listing parameters", + detail, + "group_datasets", + ) + .with_request_id(rid.clone()) + })?; let not_found_name = group.clone(); tokio::task::spawn_blocking(move || { db::get_group_by_name(&group).and_then(|group| match group { @@ -1186,13 +1199,25 @@ pub async fn group_datasets( ), ) }); + let rows: Vec = datasets + .iter() + .map(|dataset| serde_json::to_value(dataset).unwrap_or(serde_json::Value::Null)) + .collect(); + let (shaped, missing) = listing.shape(rows, params.limit_to.as_deref()); let mut envelope = ctx - .envelope(datasets) + .envelope(shaped) .with_next( &format!("/groups/{}", path_segment(¬_found_name)), "The group these datasets belong to", ) .with_links(crate::suggest::group_links(¬_found_name)); + if !missing.is_empty() { + envelope = envelope.with_note(&format!( + "limit_to named {} value(s) that matched no dataset: {}", + missing.len(), + missing.join(", ") + )); + } if let Some((href, description)) = example { envelope = envelope.with_next(&href, &description); } -- cgit 1.4.1