diff --git a/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql b/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql index a1d9124..a76f707 100644 --- a/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql +++ b/hammond-data/migrations/2017-09-15-001128_init_schema/up.sql @@ -16,11 +16,13 @@ CREATE TABLE `episode` ( `uri` TEXT NOT NULL UNIQUE, `local_uri` TEXT, `description` TEXT, - `published_date` TEXT , + `published_date` TEXT, `epoch` INTEGER NOT NULL DEFAULT 0, `length` INTEGER, `guid` TEXT, - `played` INTEGER , + `played` INTEGER, + `favorite` INTEGER NOT NULL DEFAULT 0, + `archive` INTEGER NOT NULL DEFAULT 0, `podcast_id` INTEGER NOT NULL ); @@ -30,5 +32,8 @@ CREATE TABLE `podcast` ( `link` TEXT NOT NULL, `description` TEXT NOT NULL, `image_uri` TEXT, + `favorite` INTEGER NOT NULL DEFAULT 0, + `archive` INTEGER NOT NULL DEFAULT 0, + `always_dl` INTEGER NOT NULL DEFAULT 0, `source_id` INTEGER NOT NULL ); \ No newline at end of file diff --git a/hammond-data/src/models.rs b/hammond-data/src/models.rs index de8545f..55e7423 100644 --- a/hammond-data/src/models.rs +++ b/hammond-data/src/models.rs @@ -25,6 +25,8 @@ pub struct Episode { guid: Option, /// Represent the epoch value of when the episode was last played. played: Option, + favorite: bool, + archive: bool, podcast_id: i32, } @@ -106,6 +108,22 @@ impl Episode { self.played = value; } + pub fn archive(&self) -> bool { + self.archive + } + + pub fn set_archive(&mut self, b: bool) { + self.archive = b + } + + pub fn favorite(&self) -> bool { + self.favorite + } + + pub fn set_favorite(&mut self, b: bool) { + self.favorite = b + } + pub fn save(&self, db: &Database) -> QueryResult { let tempdb = db.lock().unwrap(); self.save_changes::(&*tempdb) @@ -123,6 +141,9 @@ pub struct Podcast { link: String, description: String, image_uri: Option, + favorite: bool, + archive: bool, + always_dl: bool, source_id: i32, } @@ -163,6 +184,30 @@ impl Podcast { self.image_uri = value.map(|x| x.to_string()); } + pub fn archive(&self) -> bool { + self.archive + } + + pub fn set_archive(&mut self, b: bool) { + self.archive = b + } + + pub fn favorite(&self) -> bool { + self.favorite + } + + pub fn set_favorite(&mut self, b: bool) { + self.favorite = b + } + + pub fn always_download(&self) -> bool { + self.always_dl + } + + pub fn set_always_download(&mut self, b: bool) { + self.always_dl = b + } + pub fn save(&self, db: &Database) -> QueryResult { let tempdb = db.lock().unwrap(); self.save_changes::(&*tempdb) @@ -277,6 +322,7 @@ pub struct NewPodcast { } impl NewPodcast { + // This is meant only to be used to make unit tests easier. pub fn into_podcast(self) -> Podcast { Podcast { id: 0, @@ -285,6 +331,9 @@ impl NewPodcast { description: self.description, image_uri: self.image_uri, source_id: self.source_id, + always_dl: false, + archive: false, + favorite: false, } } } diff --git a/hammond-data/src/schema.rs b/hammond-data/src/schema.rs index 298fa4c..00aff92 100644 --- a/hammond-data/src/schema.rs +++ b/hammond-data/src/schema.rs @@ -10,6 +10,8 @@ table! { length -> Nullable, guid -> Nullable, played -> Nullable, + favorite -> Bool, + archive -> Bool, podcast_id -> Integer, } } @@ -21,6 +23,9 @@ table! { link -> Text, description -> Text, image_uri -> Nullable, + favorite -> Bool, + archive -> Bool, + always_dl -> Bool, source_id -> Integer, } }