feat: list sorting #42

Merged
matous-volf merged 9 commits from feat/list-sorting into main 2024-09-09 17:09:22 +00:00
Showing only changes of commit 9b8ef405c6 - Show all commits

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 {
coderabbitai[bot] commented 2024-09-09 17:00:59 +00:00 (Migrated from github.com)
Review

Approved: Ord trait implementation for Subtask.

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() and created_at() if they are called frequently in performance-critical sections.

**Approved: `Ord` trait implementation for `Subtask`.** 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()` and `created_at()` if they are called frequently in performance-critical sections. <!-- This is an auto-generated comment by CodeRabbit -->