feat: list sorting #42
@ -1,3 +1,4 @@
|
|||||||
|
use std::cmp::Ordering;
|
||||||
use crate::models::task::Task;
|
use crate::models::task::Task;
|
||||||
use crate::schema::subtasks;
|
use crate::schema::subtasks;
|
||||||
use chrono::NaiveDateTime;
|
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)]
|
#[derive(Insertable, Serialize, Deserialize, Validate, Clone, Debug)]
|
||||||
#[diesel(table_name = subtasks)]
|
#[diesel(table_name = subtasks)]
|
||||||
pub struct NewSubtask {
|
pub struct NewSubtask {
|
||||||
|
|||||||
|
Loading…
x
Reference in New Issue
Block a user
Approved:
Ord
trait implementation forSubtask
.The dual-layered comparison logic is well-implemented, prioritizing completion status and then ordering by creation timestamps. This is logical and efficient for the intended use case.
However, consider caching the results of
is_completed()
andcreated_at()
if they are called frequently in performance-critical sections.