diff --git a/src/routes.rs b/src/routes.rs index 3126497..52442dc 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -109,6 +109,10 @@ pub async fn skip_segments( } } + for sponsor in sponsors.values_mut() { + sponsor.segments.sort_by(|a, b| a.partial_cmp(b).unwrap()); + } + if !sponsors.is_empty() { let sponsors: Vec<&Sponsor> = sponsors.values().collect(); return content::RawJson(serde_json::to_string(&sponsors).unwrap()); diff --git a/src/structs.rs b/src/structs.rs index b155498..c70c7ef 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, Debug)] @@ -30,3 +31,9 @@ impl PartialEq for Segment { self.uuid == other.uuid } } + +impl PartialOrd for Segment { + fn partial_cmp(&self, other: &Self) -> Option { + self.segment[0].partial_cmp(&other.segment[0]) + } +}