diff --git a/entity/src/artist.rs b/entity/src/artist.rs index ce020a7..58b9598 100644 --- a/entity/src/artist.rs +++ b/entity/src/artist.rs @@ -119,17 +119,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/entity/src/artist_credit.rs b/entity/src/artist_credit.rs index d07f140..ab955dc 100644 --- a/entity/src/artist_credit.rs +++ b/entity/src/artist_credit.rs @@ -81,17 +81,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/entity/src/artist_credit_release.rs b/entity/src/artist_credit_release.rs index a235dbb..b865396 100644 --- a/entity/src/artist_credit_release.rs +++ b/entity/src/artist_credit_release.rs @@ -48,17 +48,6 @@ impl PartialEq for Model { } impl Eq for Model {} -impl PartialOrd for Model { - fn lt(&self, other: &Self) -> bool { - self.artist_credit_id.lt(&other.artist_credit_id) && self.release_id.lt(&other.release_id) - } - fn partial_cmp(&self, other: &Self) -> Option { - self.artist_credit_id - .partial_cmp(&other.artist_credit_id) - .and(self.release_id.partial_cmp(&other.release_id)) - } -} - impl Ord for Model { fn cmp(&self, other: &Self) -> std::cmp::Ordering { if self.eq(other) { @@ -68,3 +57,12 @@ impl Ord for Model { } } } + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.artist_credit_id.lt(&other.artist_credit_id) && self.release_id.lt(&other.release_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} diff --git a/entity/src/artist_credit_track.rs b/entity/src/artist_credit_track.rs index dfd9529..0fec719 100644 --- a/entity/src/artist_credit_track.rs +++ b/entity/src/artist_credit_track.rs @@ -48,17 +48,6 @@ impl PartialEq for Model { } impl Eq for Model {} -impl PartialOrd for Model { - fn lt(&self, other: &Self) -> bool { - self.artist_credit_id.lt(&other.artist_credit_id) && self.track_id.lt(&other.track_id) - } - fn partial_cmp(&self, other: &Self) -> Option { - self.artist_credit_id - .partial_cmp(&other.artist_credit_id) - .and(self.track_id.partial_cmp(&other.track_id)) - } -} - impl Ord for Model { fn cmp(&self, other: &Self) -> std::cmp::Ordering { if self.eq(other) { @@ -68,3 +57,12 @@ impl Ord for Model { } } } + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.artist_credit_id.lt(&other.artist_credit_id) && self.track_id.lt(&other.track_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} diff --git a/entity/src/artist_track_relation.rs b/entity/src/artist_track_relation.rs index 9f006b8..f142428 100644 --- a/entity/src/artist_track_relation.rs +++ b/entity/src/artist_track_relation.rs @@ -131,6 +131,16 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + if self.eq(other) { + std::cmp::Ordering::Equal + } else { + self.artist_id.cmp(&other.artist_id) + } + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.artist_id.lt(&other.artist_id) @@ -139,20 +149,6 @@ impl PartialOrd for Model { && self.relation_value.lt(&other.relation_value) } fn partial_cmp(&self, other: &Self) -> Option { - self.artist_id - .partial_cmp(&other.artist_id) - .and(self.track_id.partial_cmp(&other.track_id)) - .and(self.relation_type.partial_cmp(&other.relation_type)) - .and(self.relation_value.partial_cmp(&other.relation_value)) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - if self.eq(other) { - std::cmp::Ordering::Equal - } else { - self.artist_id.cmp(&other.artist_id) - } + Some(self.cmp(other)) } } diff --git a/entity/src/genre.rs b/entity/src/genre.rs index 4b4d985..cd3d36b 100644 --- a/entity/src/genre.rs +++ b/entity/src/genre.rs @@ -87,17 +87,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/entity/src/genre_release.rs b/entity/src/genre_release.rs index 9ba08d4..7a7488c 100644 --- a/entity/src/genre_release.rs +++ b/entity/src/genre_release.rs @@ -48,17 +48,6 @@ impl PartialEq for Model { } impl Eq for Model {} -impl PartialOrd for Model { - fn lt(&self, other: &Self) -> bool { - self.genre_id.lt(&other.genre_id) && self.release_id.lt(&other.release_id) - } - fn partial_cmp(&self, other: &Self) -> Option { - self.genre_id - .partial_cmp(&other.genre_id) - .and(self.release_id.partial_cmp(&other.release_id)) - } -} - impl Ord for Model { fn cmp(&self, other: &Self) -> std::cmp::Ordering { if self.eq(other) { @@ -68,3 +57,12 @@ impl Ord for Model { } } } + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.genre_id.lt(&other.genre_id) && self.release_id.lt(&other.release_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} diff --git a/entity/src/genre_track.rs b/entity/src/genre_track.rs index 2415645..bbb1908 100644 --- a/entity/src/genre_track.rs +++ b/entity/src/genre_track.rs @@ -49,17 +49,6 @@ impl PartialEq for Model { } impl Eq for Model {} -impl PartialOrd for Model { - fn lt(&self, other: &Self) -> bool { - self.genre_id.lt(&other.genre_id) && self.track_id.lt(&other.track_id) - } - fn partial_cmp(&self, other: &Self) -> Option { - self.genre_id - .partial_cmp(&other.genre_id) - .and(self.track_id.partial_cmp(&other.track_id)) - } -} - impl Ord for Model { fn cmp(&self, other: &Self) -> std::cmp::Ordering { if self.eq(other) { @@ -69,3 +58,12 @@ impl Ord for Model { } } } + +impl PartialOrd for Model { + fn lt(&self, other: &Self) -> bool { + self.genre_id.lt(&other.genre_id) && self.track_id.lt(&other.track_id) + } + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} diff --git a/entity/src/medium.rs b/entity/src/medium.rs index 214052d..4281f1c 100644 --- a/entity/src/medium.rs +++ b/entity/src/medium.rs @@ -80,17 +80,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/entity/src/release.rs b/entity/src/release.rs index 432e8f9..3aa840a 100644 --- a/entity/src/release.rs +++ b/entity/src/release.rs @@ -136,17 +136,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/entity/src/track.rs b/entity/src/track.rs index 1f969c1..81daf45 100644 --- a/entity/src/track.rs +++ b/entity/src/track.rs @@ -161,17 +161,17 @@ impl PartialEq for Model { } impl Eq for Model {} +impl Ord for Model { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.id.cmp(&other.id) + } +} + impl PartialOrd for Model { fn lt(&self, other: &Self) -> bool { self.id.lt(&other.id) } fn partial_cmp(&self, other: &Self) -> Option { - self.id.partial_cmp(&other.id) - } -} - -impl Ord for Model { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.id.cmp(&other.id) + Some(self.cmp(other)) } } diff --git a/server/src/api/documents.rs b/server/src/api/documents.rs index 33b827e..a30c822 100644 --- a/server/src/api/documents.rs +++ b/server/src/api/documents.rs @@ -78,14 +78,7 @@ impl Eq for Included {} impl std::cmp::PartialOrd for Included { fn partial_cmp(&self, other: &Self) -> Option { - match (self, other) { - (Included::Image(a), Included::Image(b)) => a.id.partial_cmp(&b.id), - (Included::Artist(a), Included::Artist(b)) => a.id.partial_cmp(&b.id), - (Included::Track(a), Included::Track(b)) => a.id.partial_cmp(&b.id), - (Included::Medium(a), Included::Medium(b)) => a.id.partial_cmp(&b.id), - (Included::Release(a), Included::Release(b)) => a.id.partial_cmp(&b.id), - (_, _) => None, - } + Some(self.cmp(other)) } } diff --git a/server/src/api/internal/documents.rs b/server/src/api/internal/documents.rs index 834718c..c99bb66 100644 --- a/server/src/api/internal/documents.rs +++ b/server/src/api/internal/documents.rs @@ -137,11 +137,7 @@ impl Eq for Included {} impl std::cmp::PartialOrd for Included { fn partial_cmp(&self, other: &Self) -> Option { - match (self, other) { - (Included::Directory(a), Included::Directory(b)) => a.id.partial_cmp(&b.id), - (Included::Import(a), Included::Import(b)) => a.id.partial_cmp(&b.id), - (_, _) => None, - } + Some(self.cmp(other)) } } diff --git a/server/src/api/jsonapi.rs b/server/src/api/jsonapi.rs index ebacc23..46d4258 100644 --- a/server/src/api/jsonapi.rs +++ b/server/src/api/jsonapi.rs @@ -274,7 +274,7 @@ where }) .collect() }) - .unwrap_or(HashMap::new()), + .unwrap_or_default(), page: raw_opts.page.unwrap_or_else(default_page), }; Ok(Query(opts))