Added extra columns to podcast and episode tables.

This commit is contained in:
Jordan Petridis 2017-11-15 16:58:21 +02:00
parent 8b4701f1a1
commit 118846f255
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 61 additions and 2 deletions

View File

@ -21,6 +21,8 @@ CREATE TABLE `episode` (
`length` INTEGER, `length` INTEGER,
`guid` TEXT, `guid` TEXT,
`played` INTEGER, `played` INTEGER,
`favorite` INTEGER NOT NULL DEFAULT 0,
`archive` INTEGER NOT NULL DEFAULT 0,
`podcast_id` INTEGER NOT NULL `podcast_id` INTEGER NOT NULL
); );
@ -30,5 +32,8 @@ CREATE TABLE `podcast` (
`link` TEXT NOT NULL, `link` TEXT NOT NULL,
`description` TEXT NOT NULL, `description` TEXT NOT NULL,
`image_uri` TEXT, `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 `source_id` INTEGER NOT NULL
); );

View File

@ -25,6 +25,8 @@ pub struct Episode {
guid: Option<String>, guid: Option<String>,
/// Represent the epoch value of when the episode was last played. /// Represent the epoch value of when the episode was last played.
played: Option<i32>, played: Option<i32>,
favorite: bool,
archive: bool,
podcast_id: i32, podcast_id: i32,
} }
@ -106,6 +108,22 @@ impl Episode {
self.played = value; 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<Episode> { pub fn save(&self, db: &Database) -> QueryResult<Episode> {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
self.save_changes::<Episode>(&*tempdb) self.save_changes::<Episode>(&*tempdb)
@ -123,6 +141,9 @@ pub struct Podcast {
link: String, link: String,
description: String, description: String,
image_uri: Option<String>, image_uri: Option<String>,
favorite: bool,
archive: bool,
always_dl: bool,
source_id: i32, source_id: i32,
} }
@ -163,6 +184,30 @@ impl Podcast {
self.image_uri = value.map(|x| x.to_string()); 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<Podcast> { pub fn save(&self, db: &Database) -> QueryResult<Podcast> {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
self.save_changes::<Podcast>(&*tempdb) self.save_changes::<Podcast>(&*tempdb)
@ -277,6 +322,7 @@ pub struct NewPodcast {
} }
impl NewPodcast { impl NewPodcast {
// This is meant only to be used to make unit tests easier.
pub fn into_podcast(self) -> Podcast { pub fn into_podcast(self) -> Podcast {
Podcast { Podcast {
id: 0, id: 0,
@ -285,6 +331,9 @@ impl NewPodcast {
description: self.description, description: self.description,
image_uri: self.image_uri, image_uri: self.image_uri,
source_id: self.source_id, source_id: self.source_id,
always_dl: false,
archive: false,
favorite: false,
} }
} }
} }

View File

@ -10,6 +10,8 @@ table! {
length -> Nullable<Integer>, length -> Nullable<Integer>,
guid -> Nullable<Text>, guid -> Nullable<Text>,
played -> Nullable<Integer>, played -> Nullable<Integer>,
favorite -> Bool,
archive -> Bool,
podcast_id -> Integer, podcast_id -> Integer,
} }
} }
@ -21,6 +23,9 @@ table! {
link -> Text, link -> Text,
description -> Text, description -> Text,
image_uri -> Nullable<Text>, image_uri -> Nullable<Text>,
favorite -> Bool,
archive -> Bool,
always_dl -> Bool,
source_id -> Integer, source_id -> Integer,
} }
} }