feat: implement Ord
for the subtask model
This commit is contained in:
parent
6e6d15de5c
commit
9b8ef405c6
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user