diff --git a/api/src/controllers/api/mod.rs b/api/src/controllers/api/mod.rs index 13fe3d5..66ebaac 100644 --- a/api/src/controllers/api/mod.rs +++ b/api/src/controllers/api/mod.rs @@ -1,3 +1,5 @@ +use serde::Deserialize; + pub mod pept2ec; pub mod pept2funct; pub mod pept2go; @@ -11,6 +13,19 @@ pub mod taxa2lca; pub mod taxa2tree; pub mod taxonomy; +#[derive(Deserialize)] +#[serde(untagged)] +pub enum EitherVec { + Left(Vec), + Right(Vec) +} + +impl Default for EitherVec { + fn default() -> Self { + EitherVec::Left(Vec::new()) + } +} + pub fn default_equate_il() -> bool { true } diff --git a/api/src/controllers/api/taxa2lca.rs b/api/src/controllers/api/taxa2lca.rs index aa09b0e..7cf2fa8 100644 --- a/api/src/controllers/api/taxa2lca.rs +++ b/api/src/controllers/api/taxa2lca.rs @@ -15,11 +15,12 @@ use crate::{ }, AppState }; +use crate::controllers::api::EitherVec; #[derive(Deserialize)] pub struct Parameters { #[serde(default)] - input: Vec, + input: EitherVec, #[serde(default = "default_extra")] extra: bool, #[serde(default = "default_names")] @@ -49,8 +50,13 @@ async fn handler( let taxon_store = datastore.taxon_store(); let lineage_store = datastore.lineage_store(); + let casted_input: Vec = match input { + EitherVec::Left(numbers) => numbers, + EitherVec::Right(strings) => strings.iter().map(|s| s.parse().unwrap_or_default()).collect() + }; + // Calculate the LCA of all taxa - let lca: i32 = calculate_lca(input, version, taxon_store, lineage_store); + let lca: i32 = calculate_lca(casted_input, version, taxon_store, lineage_store); if let Some((taxon_name, taxon_rank, _)) = taxon_store.get(lca as u32) { // Calculate the lineage of the LCA