Skip to content

Commit

Permalink
always sort with ala taxa on top
Browse files Browse the repository at this point in the history
  • Loading branch information
gsterjov committed Oct 27, 2024
1 parent 12b78af commit 61abd44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions server/src/http/graphql/common/taxonomy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,14 @@ impl TaxonomicRank {
}
}
}


pub fn sort_taxa_priority(taxa: &mut Vec<models::TaxonWithDataset>) {
use std::cmp::Ordering;

taxa.sort_by(|a, b| match (a.dataset.name.as_str(), b.dataset.name.as_str()) {
("Atlas of Living Australia", _) => Ordering::Less,
(_, "Atlas of Living Australia") => Ordering::Greater,
_ => a.dataset.name.cmp(&b.dataset.name),
});
}
3 changes: 2 additions & 1 deletion server/src/http/graphql/species.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
use tracing::instrument;
use uuid::Uuid;

use super::common::taxonomy::sort_taxa_priority;
use super::common::{
convert_whole_genome_filters,
DatasetDetails,
Expand Down Expand Up @@ -125,7 +126,7 @@ impl Species {
let mut all_taxa = state.database.taxa.find_by_classification(&classification).await?;

// sort by dataset name for some consistency
all_taxa.sort_by(|a, b| a.dataset.name.cmp(&b.dataset.name));
sort_taxa_priority(&mut all_taxa);
let taxon = all_taxa
.get(0)
.ok_or_else(|| Error::NotFound(self.canonical_name.clone()))?;
Expand Down
4 changes: 2 additions & 2 deletions server/src/http/graphql/taxon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use super::common::datasets::DatasetDetails;
use super::common::taxonomy::{NomenclaturalActType, TaxonDetails, TaxonomicRank, TaxonomicStatus};
use super::common::taxonomy::{sort_taxa_priority, NomenclaturalActType, TaxonDetails, TaxonomicRank, TaxonomicStatus};
use super::common::{NameDetails, Page, SpeciesCard};
use super::helpers::SpeciesHelper;
use super::specimen::SpecimenDetails;
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Taxon {
let mut taxa = db.taxa.find_by_classification(&classification).await?;

// sort by dataset name for some consistency
taxa.sort_by(|a, b| a.dataset.name.cmp(&b.dataset.name));
sort_taxa_priority(&mut taxa);
let taxon = taxa.first().ok_or_else(|| Error::NotFound(canonical_name))?;
let details: TaxonDetails = taxon.clone().into();

Expand Down

0 comments on commit 61abd44

Please sign in to comment.