feat: implement Ord for the subtask model

This commit is contained in:
Matouš Volf 2024-09-09 18:49:28 +02:00
parent bec9859d20
commit 1cc8cfe0d4

View File

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use crate::models::task::Task;
use crate::schema::subtasks;
use chrono::NaiveDateTime;
@ -48,6 +49,21 @@ impl Subtask {
}
}
impl Eq for Subtask {}
impl PartialOrd<Self> for Subtask {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Subtask {
fn cmp(&self, other: &Self) -> Ordering {
self.is_completed().cmp(&other.is_completed())
.then(self.created_at().cmp(&other.created_at()))
}
}
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
#[diesel(table_name = subtasks)]
pub struct NewSubtask {