diff options
Diffstat (limited to 'src')
| -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); } |
