Skip to content

Commit

Permalink
Return empty vector if filter not found
Browse files Browse the repository at this point in the history
Return an empty vector from the configurations query if a beamlineFilter
is provided but does not match a beamline, previously the API returned
an error in this case.
  • Loading branch information
callumforrester committed Dec 10, 2024
1 parent 015d27b commit cf8edda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/db_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl fmt::Debug for SqliteScanPathService {
}
}

mod error {
pub(crate) mod error {
use std::error::Error;
use std::fmt::{self, Display};

Expand Down
15 changes: 10 additions & 5 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::cli::ServeOptions;
use crate::db_service::{
BeamlineConfiguration, BeamlineConfigurationUpdate, SqliteScanPathService,
};
use crate::db_service::error::ConfigurationError;
use crate::numtracker::GdaNumTracker;
use crate::paths::{
BeamlineField, DetectorField, DetectorTemplate, PathSpec, ScanField, ScanTemplate,
Expand Down Expand Up @@ -265,17 +266,21 @@ impl Query {
beamline_filter: Option<String>,
) -> async_graphql::Result<Vec<BeamlineConfiguration>> {
let db = ctx.data::<SqliteScanPathService>()?;
match beamline_filter {
let matching = match beamline_filter {
Some(filter) => {
trace!("Getting configs matching {filter:?}");
let singleton = db.current_configuration(&filter).await?;
Ok(vec![singleton])
match db.current_configuration(&filter).await {
Ok(configuration) => vec![configuration],
Err(ConfigurationError::MissingBeamline(_)) => vec![],
Err(other) => Err(other)?
}
}
None => {
trace!("Getting all configs");
Ok(db.configurations().await?)
db.configurations().await?
}
}
};
Ok(matching)
}
}

Expand Down

0 comments on commit cf8edda

Please sign in to comment.