diff options
Diffstat (limited to 'src/task.rs')
-rw-r--r-- | src/task.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/task.rs b/src/task.rs index dcfe776..59aa502 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,36 +1,52 @@ use std::{ borrow::{Borrow, Cow}, + collections::HashSet, str::FromStr, }; use chrono::{NaiveDateTime, TimeDelta}; use sqlx::{ encode::IsNull, + prelude::FromRow, sqlite::{SqliteArgumentValue, SqliteTypeInfo, SqliteValue}, Decode, Sqlite, Type, TypeInfo, Value, ValueRef, }; +#[derive(FromRow)] pub struct Task { + id: Option<i64>, pub name: String, pub cron: Option<Schedule>, pub archived: bool, pub description: Option<String>, + pub categories: HashSet<String>, } impl Task { pub fn new( name: String, cron: Option<Schedule>, - archived: bool, description: Option<String>, + categories: Option<HashSet<String>>, ) -> Self { Self { + id: None, name, cron, - archived, + archived: false, description, + categories: categories.unwrap_or_else(|| HashSet::new()), } } + + pub fn id(&self) -> Option<i64> { + self.id + } + + pub fn add_id(mut self, id: i64) -> Self { + self.id = Some(id); + self + } } pub struct Schedule(cron::Schedule); @@ -64,6 +80,7 @@ impl Type<Sqlite> for Schedule { } } +#[repr(transparent)] pub struct Category(String); impl Category { |