diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-17 12:15:56 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-17 12:15:56 +0000 |
| commit | 5419674c1f6635f31095b95ff4c1d5ca0e4fbcdc (patch) | |
| tree | 455a8a37a7e3b96667ef52030e95500dfcd4329a | |
| parent | b055c240c909e5c3628cc341fe1a2cbae9ed07f6 (diff) | |
| download | genenetwork4-5419674c1f6635f31095b95ff4c1d5ca0e4fbcdc.tar.gz | |
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.
| -rw-r--r-- | src/listing.rs | 4 | ||||
| -rw-r--r-- | src/routes/groups.rs | 31 |
2 files changed, 30 insertions, 5 deletions
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<String>), } -/// 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<Vec<db::Dataset>>), + (status = 200, description = "The expression (ProbeSet) datasets belonging to the group; \ +`ids_only`/`names_only` answer one value per dataset instead", body = Envelope<crate::listing::Rows>), 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<String>, _token: AuthToken, -) -> Result<Json<Envelope<Vec<db::Dataset>>>, ApiError> { + Query(params): 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(¶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<serde_json::Value> = 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); } |
