Document Podcast Model.

This commit is contained in:
Jordan Petridis 2017-11-28 08:40:27 +02:00
parent 3707b70b41
commit 4d669ef297
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -28,11 +28,9 @@ pub struct Episode {
local_uri: Option<String>, local_uri: Option<String>,
description: Option<String>, description: Option<String>,
published_date: Option<String>, published_date: Option<String>,
/// Representation of system time. Should be in UTC.
epoch: i32, epoch: i32,
length: Option<i32>, length: Option<i32>,
guid: Option<String>, guid: Option<String>,
/// Represent the epoch value of when the episode was last played.
played: Option<i32>, played: Option<i32>,
favorite: bool, favorite: bool,
archive: bool, archive: bool,
@ -72,7 +70,7 @@ impl Episode {
self.local_uri = value.map(|x| x.to_string()); self.local_uri = value.map(|x| x.to_string());
} }
/// Get the value of the `description`. /// Get the `description`.
pub fn description(&self) -> Option<&str> { pub fn description(&self) -> Option<&str> {
self.description.as_ref().map(|s| s.as_str()) self.description.as_ref().map(|s| s.as_str())
} }
@ -104,6 +102,7 @@ impl Episode {
/// Get the `epoch` value. /// Get the `epoch` value.
/// Retrieved from the rss Item publish date. /// Retrieved from the rss Item publish date.
/// Set to Utc whenever possible.
pub fn epoch(&self) -> i32 { pub fn epoch(&self) -> i32 {
self.epoch self.epoch
} }
@ -146,17 +145,17 @@ impl Episode {
self.archive = b self.archive = b
} }
/// Get the `favorite` statues of the `Episode`. /// Get the `favorite` status of the `Episode`.
pub fn favorite(&self) -> bool { pub fn favorite(&self) -> bool {
self.favorite self.favorite
} }
/// Set `favorite`. /// Set `favorite` status.
pub fn set_favorite(&mut self, b: bool) { pub fn set_favorite(&mut self, b: bool) {
self.favorite = b self.favorite = b
} }
/// `Podcast` foreign key. /// `Podcast` table foreign key.
pub fn podcast_id(&self) -> i32 { pub fn podcast_id(&self) -> i32 {
self.podcast_id self.podcast_id
} }
@ -183,6 +182,7 @@ impl Episode {
#[changeset_options(treat_none_as_null = "true")] #[changeset_options(treat_none_as_null = "true")]
#[table_name = "podcast"] #[table_name = "podcast"]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Diesel Model of the podcast table.
pub struct Podcast { pub struct Podcast {
id: i32, id: i32,
title: String, title: String,
@ -196,62 +196,81 @@ pub struct Podcast {
} }
impl Podcast { impl Podcast {
pub fn source_id(&self) -> i32 { /// Get the Feed `title`.
self.source_id
}
pub fn title(&self) -> &str { pub fn title(&self) -> &str {
&self.title &self.title
} }
/// Get the Feed `link`.
/// Usually the website/homepage of the content creator.
pub fn link(&self) -> &str { pub fn link(&self) -> &str {
&self.link &self.link
} }
/// Set the Podcast/Feed `link`.
pub fn set_link(&mut self, value: &str) { pub fn set_link(&mut self, value: &str) {
self.link = value.to_string(); self.link = value.to_string();
} }
/// Get the `description`.
pub fn description(&self) -> &str { pub fn description(&self) -> &str {
&self.description &self.description
} }
/// Set the `description`.
pub fn set_description(&mut self, value: &str) { pub fn set_description(&mut self, value: &str) {
self.description = value.to_string(); self.description = value.to_string();
} }
/// Get the `image_uri`.
/// Represents the uri(url usually) that the Feed cover image is located at.
pub fn image_uri(&self) -> Option<&str> { pub fn image_uri(&self) -> Option<&str> {
self.image_uri.as_ref().map(|s| s.as_str()) self.image_uri.as_ref().map(|s| s.as_str())
} }
/// Set the `image_uri`.
pub fn set_image_uri(&mut self, value: Option<&str>) { pub fn set_image_uri(&mut self, value: Option<&str>) {
self.image_uri = value.map(|x| x.to_string()); self.image_uri = value.map(|x| x.to_string());
} }
/// Represents the archiving policy for the episode.
pub fn archive(&self) -> bool { pub fn archive(&self) -> bool {
self.archive self.archive
} }
/// Set the `archive` policy.
pub fn set_archive(&mut self, b: bool) { pub fn set_archive(&mut self, b: bool) {
self.archive = b self.archive = b
} }
/// Get the `favorite` status of the `Podcast` Feed.
pub fn favorite(&self) -> bool { pub fn favorite(&self) -> bool {
self.favorite self.favorite
} }
/// Set `favorite` status.
pub fn set_favorite(&mut self, b: bool) { pub fn set_favorite(&mut self, b: bool) {
self.favorite = b self.favorite = b
} }
/// Represents the download policy for the `Podcast` Feed.
/// Reserved for the use with a Download manager, yet to be implemented.
/// If true Podcast Episode should be downloaded automaticly/skipping the selection queue.
pub fn always_download(&self) -> bool { pub fn always_download(&self) -> bool {
self.always_dl self.always_dl
} }
/// Set the download policy.
pub fn set_always_download(&mut self, b: bool) { pub fn set_always_download(&mut self, b: bool) {
self.always_dl = b self.always_dl = b
} }
/// `Source` table foreign key.
pub fn source_id(&self) -> i32 {
self.source_id
}
/// Helper method to easily save/"sync" current state of self to the Database.
pub fn save(&self) -> Result<Podcast> { pub fn save(&self) -> Result<Podcast> {
let db = connection(); let db = connection();
let tempdb = db.get()?; let tempdb = db.get()?;