feat: implement Ord for the subtask model
				
					
				
			This commit is contained in:
		| @@ -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 { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Matouš Volf
					Matouš Volf