Models: Rename Podcat Models to Show to better match the UI code.

This commit is contained in:
Jordan Petridis 2018-06-30 22:47:58 +03:00
parent 400c0f35f0
commit 2d66ba918a
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
14 changed files with 116 additions and 116 deletions

View File

@ -23,18 +23,18 @@ pub fn get_sources() -> Result<Vec<Source>, DataError> {
.map_err(From::from) .map_err(From::from)
} }
pub fn get_podcasts() -> Result<Vec<Podcast>, DataError> { pub fn get_podcasts() -> Result<Vec<Show>, DataError> {
use schema::shows::dsl::*; use schema::shows::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
shows shows
.order(title.asc()) .order(title.asc())
.load::<Podcast>(&con) .load::<Show>(&con)
.map_err(From::from) .map_err(From::from)
} }
pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Podcast>, DataError> { pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Show>, DataError> {
use schema::shows::dsl::*; use schema::shows::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -42,7 +42,7 @@ pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Podcast>, DataError
shows shows
.order(title.asc()) .order(title.asc())
.filter(id.ne_all(filter_ids)) .filter(id.ne_all(filter_ids))
.load::<Podcast>(&con) .load::<Show>(&con)
.map_err(From::from) .map_err(From::from)
} }
@ -149,18 +149,18 @@ pub fn get_episodes_widgets_filter_limit(
.map_err(From::from) .map_err(From::from)
} }
pub fn get_podcast_from_id(pid: i32) -> Result<Podcast, DataError> { pub fn get_podcast_from_id(pid: i32) -> Result<Show, DataError> {
use schema::shows::dsl::*; use schema::shows::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
shows shows
.filter(id.eq(pid)) .filter(id.eq(pid))
.get_result::<Podcast>(&con) .get_result::<Show>(&con)
.map_err(From::from) .map_err(From::from)
} }
pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery, DataError> { pub fn get_podcast_cover_from_id(pid: i32) -> Result<ShowCoverQuery, DataError> {
use schema::shows::dsl::*; use schema::shows::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -168,11 +168,11 @@ pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery, DataErro
shows shows
.select((id, title, image_uri)) .select((id, title, image_uri))
.filter(id.eq(pid)) .filter(id.eq(pid))
.get_result::<PodcastCoverQuery>(&con) .get_result::<ShowCoverQuery>(&con)
.map_err(From::from) .map_err(From::from)
} }
pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> { pub fn get_pd_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
use schema::episodes::dsl::*; use schema::episodes::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -183,7 +183,7 @@ pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
.map_err(From::from) .map_err(From::from)
} }
pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> { pub fn get_pd_episodes_count(parent: &Show) -> Result<i64, DataError> {
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -193,7 +193,7 @@ pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> {
.map_err(From::from) .map_err(From::from)
} }
pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery>, DataError> { pub fn get_pd_episodeswidgets(parent: &Show) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
use schema::episodes::dsl::*; use schema::episodes::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -209,7 +209,7 @@ pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery
.map_err(From::from) .map_err(From::from)
} }
pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> { pub fn get_pd_unplayed_episodes(parent: &Show) -> Result<Vec<Episode>, DataError> {
use schema::episodes::dsl::*; use schema::episodes::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -221,7 +221,7 @@ pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataEr
.map_err(From::from) .map_err(From::from)
} }
// pub(crate) fn get_pd_episodes_limit(parent: &Podcast, limit: u32) -> // pub(crate) fn get_pd_episodes_limit(parent: &Show, limit: u32) ->
// Result<Vec<Episode>, DataError> { use schema::episodes::dsl::*; // Result<Vec<Episode>, DataError> { use schema::episodes::dsl::*;
// let db = connection(); // let db = connection();
@ -256,14 +256,14 @@ pub fn get_source_from_id(id_: i32) -> Result<Source, DataError> {
.map_err(From::from) .map_err(From::from)
} }
pub fn get_podcast_from_source_id(sid: i32) -> Result<Podcast, DataError> { pub fn get_podcast_from_source_id(sid: i32) -> Result<Show, DataError> {
use schema::shows::dsl::*; use schema::shows::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
shows shows
.filter(source_id.eq(sid)) .filter(source_id.eq(sid))
.get_result::<Podcast>(&con) .get_result::<Show>(&con)
.map_err(From::from) .map_err(From::from)
} }
@ -295,7 +295,7 @@ pub(crate) fn get_episode_minimal_from_pk(
.map_err(From::from) .map_err(From::from)
} }
pub(crate) fn remove_feed(pd: &Podcast) -> Result<(), DataError> { pub(crate) fn remove_feed(pd: &Show) -> Result<(), DataError> {
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;
@ -400,7 +400,7 @@ pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
.map(|_| ()) .map(|_| ())
} }
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize, DataError> { pub fn update_none_to_played_now(parent: &Show) -> Result<usize, DataError> {
use schema::episodes::dsl::*; use schema::episodes::dsl::*;
let db = connection(); let db = connection();
let con = db.get()?; let con = db.get()?;

View File

@ -9,7 +9,7 @@ use rss;
use dbqueries; use dbqueries;
use errors::DataError; use errors::DataError;
use models::{Index, IndexState, Update}; use models::{Index, IndexState, Update};
use models::{NewEpisode, NewEpisodeMinimal, NewPodcast, Podcast}; use models::{NewEpisode, NewEpisodeMinimal, NewShow, Show};
/// Wrapper struct that hold a `Source` id and the `rss::Channel` /// Wrapper struct that hold a `Source` id and the `rss::Channel`
/// that corresponds to the `Source.uri` field. /// that corresponds to the `Source.uri` field.
@ -31,15 +31,15 @@ impl Feed {
.and_then(move |pd| self.index_channel_items(pd)) .and_then(move |pd| self.index_channel_items(pd))
} }
fn parse_podcast(&self) -> NewPodcast { fn parse_podcast(&self) -> NewShow {
NewPodcast::new(&self.channel, self.source_id) NewShow::new(&self.channel, self.source_id)
} }
fn parse_podcast_async(&self) -> impl Future<Item = NewPodcast, Error = DataError> + Send { fn parse_podcast_async(&self) -> impl Future<Item = NewShow, Error = DataError> + Send {
ok(self.parse_podcast()) ok(self.parse_podcast())
} }
fn index_channel_items(self, pd: Podcast) -> impl Future<Item = (), Error = DataError> + Send { fn index_channel_items(self, pd: Show) -> impl Future<Item = (), Error = DataError> + Send {
let stream = stream::iter_ok::<_, DataError>(self.channel.into_items()); let stream = stream::iter_ok::<_, DataError>(self.channel.into_items());
// Parse the episodes // Parse the episodes
@ -204,7 +204,7 @@ mod tests {
let file = fs::File::open(path).unwrap(); let file = fs::File::open(path).unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(feed.parse_podcast(), pd); assert_eq!(feed.parse_podcast(), pd);
} }

View File

@ -81,7 +81,7 @@ pub mod utils;
pub use feed::{Feed, FeedBuilder}; pub use feed::{Feed, FeedBuilder};
pub use models::Save; pub use models::Save;
pub use models::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source}; pub use models::{Episode, EpisodeWidgetQuery, Show, ShowCoverQuery, Source};
// Set the user agent, See #53 for more // Set the user agent, See #53 for more
// Keep this in sync with Tor-browser releases // Keep this in sync with Tor-browser releases

View File

@ -5,14 +5,14 @@ use diesel::SaveChangesDsl;
use database::connection; use database::connection;
use errors::DataError; use errors::DataError;
use models::{Podcast, Save}; use models::{Save, Show};
use schema::episodes; use schema::episodes;
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)] #[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
#[table_name = "episodes"] #[table_name = "episodes"]
#[changeset_options(treat_none_as_null = "true")] #[changeset_options(treat_none_as_null = "true")]
#[primary_key(title, show_id)] #[primary_key(title, show_id)]
#[belongs_to(Podcast, foreign_key = "show_id")] #[belongs_to(Show, foreign_key = "show_id")]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Diesel Model of the episode table. /// Diesel Model of the episode table.
pub struct Episode { pub struct Episode {
@ -152,7 +152,7 @@ impl Episode {
self.played = value; self.played = value;
} }
/// `Podcast` table foreign key. /// `Show` table foreign key.
pub fn show_id(&self) -> i32 { pub fn show_id(&self) -> i32 {
self.show_id self.show_id
} }
@ -292,7 +292,7 @@ impl EpisodeWidgetQuery {
self.played = value; self.played = value;
} }
/// `Podcast` table foreign key. /// `Show` table foreign key.
pub fn show_id(&self) -> i32 { pub fn show_id(&self) -> i32 {
self.show_id self.show_id
} }
@ -445,7 +445,7 @@ impl EpisodeMinimal {
self.duration self.duration
} }
/// `Podcast` table foreign key. /// `Show` table foreign key.
pub fn show_id(&self) -> i32 { pub fn show_id(&self) -> i32 {
self.show_id self.show_id
} }

View File

@ -1,9 +1,9 @@
mod new_episode; mod new_episode;
mod new_podcast; mod new_show;
mod new_source; mod new_source;
mod episode; mod episode;
mod podcast; mod show;
mod source; mod source;
// use futures::prelude::*; // use futures::prelude::*;
@ -11,16 +11,16 @@ mod source;
pub(crate) use self::episode::EpisodeCleanerQuery; pub(crate) use self::episode::EpisodeCleanerQuery;
pub(crate) use self::new_episode::{NewEpisode, NewEpisodeMinimal}; pub(crate) use self::new_episode::{NewEpisode, NewEpisodeMinimal};
pub(crate) use self::new_podcast::NewPodcast; pub(crate) use self::new_show::NewShow;
pub(crate) use self::new_source::NewSource; pub(crate) use self::new_source::NewSource;
#[cfg(test)] #[cfg(test)]
pub(crate) use self::new_episode::NewEpisodeBuilder; pub(crate) use self::new_episode::NewEpisodeBuilder;
#[cfg(test)] #[cfg(test)]
pub(crate) use self::new_podcast::NewPodcastBuilder; pub(crate) use self::new_show::NewShowBuilder;
pub use self::episode::{Episode, EpisodeMinimal, EpisodeWidgetQuery}; pub use self::episode::{Episode, EpisodeMinimal, EpisodeWidgetQuery};
pub use self::podcast::{Podcast, PodcastCoverQuery}; pub use self::show::{Show, ShowCoverQuery};
pub use self::source::Source; pub use self::source::Source;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]

View File

@ -4,7 +4,7 @@ use diesel::prelude::*;
use rss; use rss;
use errors::DataError; use errors::DataError;
use models::Podcast; use models::Show;
use models::{Index, Insert, Update}; use models::{Index, Insert, Update};
use schema::shows; use schema::shows;
@ -18,7 +18,7 @@ use utils::url_cleaner;
#[builder(default)] #[builder(default)]
#[builder(derive(Debug))] #[builder(derive(Debug))]
#[builder(setter(into))] #[builder(setter(into))]
pub(crate) struct NewPodcast { pub(crate) struct NewShow {
title: String, title: String,
link: String, link: String,
description: String, description: String,
@ -26,7 +26,7 @@ pub(crate) struct NewPodcast {
source_id: i32, source_id: i32,
} }
impl Insert<()> for NewPodcast { impl Insert<()> for NewShow {
type Error = DataError; type Error = DataError;
fn insert(&self) -> Result<(), Self::Error> { fn insert(&self) -> Result<(), Self::Error> {
@ -42,7 +42,7 @@ impl Insert<()> for NewPodcast {
} }
} }
impl Update<()> for NewPodcast { impl Update<()> for NewShow {
type Error = DataError; type Error = DataError;
fn update(&self, show_id: i32) -> Result<(), Self::Error> { fn update(&self, show_id: i32) -> Result<(), Self::Error> {
@ -61,7 +61,7 @@ impl Update<()> for NewPodcast {
// TODO: Maybe return an Enum<Action(Resut)> Instead. // TODO: Maybe return an Enum<Action(Resut)> Instead.
// It would make unti testing better too. // It would make unti testing better too.
impl Index<()> for NewPodcast { impl Index<()> for NewShow {
type Error = DataError; type Error = DataError;
fn index(&self) -> Result<(), DataError> { fn index(&self) -> Result<(), DataError> {
@ -81,8 +81,8 @@ impl Index<()> for NewPodcast {
} }
} }
impl PartialEq<Podcast> for NewPodcast { impl PartialEq<Show> for NewShow {
fn eq(&self, other: &Podcast) -> bool { fn eq(&self, other: &Show) -> bool {
(self.link() == other.link()) (self.link() == other.link())
&& (self.title() == other.title()) && (self.title() == other.title())
&& (self.image_uri() == other.image_uri()) && (self.image_uri() == other.image_uri())
@ -91,9 +91,9 @@ impl PartialEq<Podcast> for NewPodcast {
} }
} }
impl NewPodcast { impl NewShow {
/// Parses a `rss::Channel` into a `NewPodcast` Struct. /// Parses a `rss::Channel` into a `NewShow` Struct.
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast { pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewShow {
let title = chan.title().trim(); let title = chan.title().trim();
let link = url_cleaner(chan.link().trim()); let link = url_cleaner(chan.link().trim());
@ -111,7 +111,7 @@ impl NewPodcast {
// If itunes is None, try to get the channel.image from the rss spec // If itunes is None, try to get the channel.image from the rss spec
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned())); let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned()));
NewPodcastBuilder::default() NewShowBuilder::default()
.title(title) .title(title)
.description(description) .description(description)
.link(link) .link(link)
@ -122,14 +122,14 @@ impl NewPodcast {
} }
// Look out for when tryinto lands into stable. // Look out for when tryinto lands into stable.
pub(crate) fn to_podcast(&self) -> Result<Podcast, DataError> { pub(crate) fn to_podcast(&self) -> Result<Show, DataError> {
self.index()?; self.index()?;
dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from) dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from)
} }
} }
// Ignore the following geters. They are used in unit tests mainly. // Ignore the following geters. They are used in unit tests mainly.
impl NewPodcast { impl NewShow {
#[allow(dead_code)] #[allow(dead_code)]
pub(crate) fn source_id(&self) -> i32 { pub(crate) fn source_id(&self) -> i32 {
self.source_id self.source_id
@ -160,14 +160,14 @@ mod tests {
use rss::Channel; use rss::Channel;
use database::truncate_db; use database::truncate_db;
use models::NewPodcastBuilder; use models::NewShowBuilder;
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
// Pre-built expected NewPodcast structs. // Pre-built expected NewShow structs.
lazy_static! { lazy_static! {
static ref EXPECTED_INTERCEPTED: NewPodcast = { static ref EXPECTED_INTERCEPTED: NewShow = {
let descr = "The people behind The Intercepts fearless reporting and incisive \ let descr = "The people behind The Intercepts fearless reporting and incisive \
commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and \ commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and \
othersdiscuss the crucial issues of our time: national security, civil \ othersdiscuss the crucial issues of our time: national security, civil \
@ -175,7 +175,7 @@ mod tests {
artists, thinkers, and newsmakers who challenge our preconceptions about \ artists, thinkers, and newsmakers who challenge our preconceptions about \
the world we live in."; the world we live in.";
NewPodcastBuilder::default() NewShowBuilder::default()
.title("Intercepted with Jeremy Scahill") .title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts") .link("https://theintercept.com/podcasts")
.description(descr) .description(descr)
@ -188,12 +188,12 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref EXPECTED_LUP: NewPodcast = { static ref EXPECTED_LUP: NewShow = {
let descr = "An open show powered by community LINUX Unplugged takes the best \ let descr = "An open show powered by community LINUX Unplugged takes the best \
attributes of open collaboration and focuses them into a weekly \ attributes of open collaboration and focuses them into a weekly \
lifestyle show about Linux."; lifestyle show about Linux.";
NewPodcastBuilder::default() NewShowBuilder::default()
.title("LINUX Unplugged Podcast") .title("LINUX Unplugged Podcast")
.link("http://www.jupiterbroadcasting.com/") .link("http://www.jupiterbroadcasting.com/")
.description(descr) .description(descr)
@ -204,7 +204,7 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref EXPECTED_TIPOFF: NewPodcast = { static ref EXPECTED_TIPOFF: NewShow = {
let desc = "<p>Welcome to The Tip Off- the podcast where we take you behind the \ let desc = "<p>Welcome to The Tip Off- the podcast where we take you behind the \
scenes of some of the best investigative journalism from recent years. \ scenes of some of the best investigative journalism from recent years. \
Each episode well be digging into an investigative scoop- hearing from \ Each episode well be digging into an investigative scoop- hearing from \
@ -215,7 +215,7 @@ mod tests {
complicated detective work that goes into doing great investigative \ complicated detective work that goes into doing great investigative \
journalism- then this is the podcast for you.</p>"; journalism- then this is the podcast for you.</p>";
NewPodcastBuilder::default() NewShowBuilder::default()
.title("The Tip Off") .title("The Tip Off")
.link("http://www.acast.com/thetipoff") .link("http://www.acast.com/thetipoff")
.description(desc) .description(desc)
@ -227,7 +227,7 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref EXPECTED_STARS: NewPodcast = { static ref EXPECTED_STARS: NewShow = {
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars \ let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars \
is a gripping noir science fiction thriller in 14 episodes: Forbidden \ is a gripping noir science fiction thriller in 14 episodes: Forbidden \
love, a crashed UFO, an alien body, and an impossible heist unlike any \ love, a crashed UFO, an alien body, and an impossible heist unlike any \
@ -237,7 +237,7 @@ mod tests {
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\ b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg"; 923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
NewPodcastBuilder::default() NewShowBuilder::default()
.title("Steal the Stars") .title("Steal the Stars")
.link("http://tor-labs.com/") .link("http://tor-labs.com/")
.description(descr) .description(descr)
@ -246,12 +246,12 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref EXPECTED_CODE: NewPodcast = { static ref EXPECTED_CODE: NewShow = {
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \ let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \
David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \ David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \
Livingston-Gray. Brought to you by @therubyrep."; Livingston-Gray. Brought to you by @therubyrep.";
NewPodcastBuilder::default() NewShowBuilder::default()
.title("Greater Than Code") .title("Greater Than Code")
.link("https://www.greaterthancode.com/") .link("https://www.greaterthancode.com/")
.description(descr) .description(descr)
@ -262,8 +262,8 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref EXPECTED_ELLINOFRENEIA: NewPodcast = { static ref EXPECTED_ELLINOFRENEIA: NewShow = {
NewPodcastBuilder::default() NewShowBuilder::default()
.title("Ελληνοφρένεια") .title("Ελληνοφρένεια")
.link("https://ellinofreneia.sealabs.net/feed.rss") .link("https://ellinofreneia.sealabs.net/feed.rss")
.description("Ανεπίσημο feed της Ελληνοφρένειας") .description("Ανεπίσημο feed της Ελληνοφρένειας")
@ -272,8 +272,8 @@ mod tests {
.build() .build()
.unwrap() .unwrap()
}; };
static ref UPDATED_DESC_INTERCEPTED: NewPodcast = { static ref UPDATED_DESC_INTERCEPTED: NewShow = {
NewPodcastBuilder::default() NewShowBuilder::default()
.title("Intercepted with Jeremy Scahill") .title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts") .link("https://theintercept.com/podcasts")
.description("New Description") .description("New Description")
@ -293,7 +293,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_INTERCEPTED, pd); assert_eq!(*EXPECTED_INTERCEPTED, pd);
} }
@ -302,7 +302,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_LUP, pd); assert_eq!(*EXPECTED_LUP, pd);
} }
@ -311,7 +311,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_TIPOFF, pd); assert_eq!(*EXPECTED_TIPOFF, pd);
} }
@ -320,7 +320,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_STARS, pd); assert_eq!(*EXPECTED_STARS, pd);
} }
@ -329,7 +329,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_CODE, pd); assert_eq!(*EXPECTED_CODE, pd);
} }
@ -338,7 +338,7 @@ mod tests {
let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").unwrap(); let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let pd = NewPodcast::new(&channel, 42); let pd = NewShow::new(&channel, 42);
assert_eq!(*EXPECTED_ELLINOFRENEIA, pd); assert_eq!(*EXPECTED_ELLINOFRENEIA, pd);
} }
@ -349,7 +349,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap(); let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap(); let channel = Channel::read_from(BufReader::new(file)).unwrap();
let npd = NewPodcast::new(&channel, 42); let npd = NewShow::new(&channel, 42);
npd.insert().unwrap(); npd.insert().unwrap();
let pd = dbqueries::get_podcast_from_source_id(42).unwrap(); let pd = dbqueries::get_podcast_from_source_id(42).unwrap();
@ -388,14 +388,14 @@ mod tests {
assert!(EXPECTED_INTERCEPTED.index().is_ok()); assert!(EXPECTED_INTERCEPTED.index().is_ok());
// Get the podcast // Get the podcast
let old = dbqueries::get_podcast_from_source_id(42).unwrap(); let old = dbqueries::get_podcast_from_source_id(42).unwrap();
// Assert that NewPodcast is equal to the Indexed one // Assert that NewShow is equal to the Indexed one
assert_eq!(&*EXPECTED_INTERCEPTED, &old); assert_eq!(&*EXPECTED_INTERCEPTED, &old);
let updated = &*UPDATED_DESC_INTERCEPTED; let updated = &*UPDATED_DESC_INTERCEPTED;
// Update the podcast // Update the podcast
assert!(updated.index().is_ok()); assert!(updated.index().is_ok());
// Get the new Podcast // Get the new Show
let new = dbqueries::get_podcast_from_source_id(42).unwrap(); let new = dbqueries::get_podcast_from_source_id(42).unwrap();
// Assert it's diff from the old one. // Assert it's diff from the old one.
assert_ne!(new, old); assert_ne!(new, old);

View File

@ -11,7 +11,7 @@ use schema::shows;
#[table_name = "shows"] #[table_name = "shows"]
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Diesel Model of the shows table. /// Diesel Model of the shows table.
pub struct Podcast { pub struct Show {
id: i32, id: i32,
title: String, title: String,
link: String, link: String,
@ -20,20 +20,20 @@ pub struct Podcast {
source_id: i32, source_id: i32,
} }
impl Save<Podcast> for Podcast { impl Save<Show> for Show {
type Error = DataError; type Error = DataError;
/// Helper method to easily save/"sync" current state of self to the /// Helper method to easily save/"sync" current state of self to the
/// Database. /// Database.
fn save(&self) -> Result<Podcast, Self::Error> { fn save(&self) -> Result<Show, Self::Error> {
let db = connection(); let db = connection();
let tempdb = db.get()?; let tempdb = db.get()?;
self.save_changes::<Podcast>(&*tempdb).map_err(From::from) self.save_changes::<Show>(&*tempdb).map_err(From::from)
} }
} }
impl Podcast { impl Show {
/// Get the Feed `id`. /// Get the Feed `id`.
pub fn id(&self) -> i32 { pub fn id(&self) -> i32 {
self.id self.id
@ -51,7 +51,7 @@ impl Podcast {
&self.link &self.link
} }
/// Set the Podcast/Feed `link`. /// Set the Show/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();
} }
@ -85,17 +85,17 @@ impl Podcast {
} }
#[derive(Queryable, Debug, Clone)] #[derive(Queryable, Debug, Clone)]
/// Diesel Model of the podcast cover query. /// Diesel Model of the Show cover query.
/// Used for fetching information about a Podcast's cover. /// Used for fetching information about a Show's cover.
pub struct PodcastCoverQuery { pub struct ShowCoverQuery {
id: i32, id: i32,
title: String, title: String,
image_uri: Option<String>, image_uri: Option<String>,
} }
impl From<Podcast> for PodcastCoverQuery { impl From<Show> for ShowCoverQuery {
fn from(p: Podcast) -> PodcastCoverQuery { fn from(p: Show) -> ShowCoverQuery {
PodcastCoverQuery { ShowCoverQuery {
id: p.id(), id: p.id(),
title: p.title, title: p.title,
image_uri: p.image_uri, image_uri: p.image_uri,
@ -103,7 +103,7 @@ impl From<Podcast> for PodcastCoverQuery {
} }
} }
impl PodcastCoverQuery { impl ShowCoverQuery {
/// Get the Feed `id`. /// Get the Feed `id`.
pub fn id(&self) -> i32 { pub fn id(&self) -> i32 {
self.id self.id

View File

@ -7,7 +7,7 @@ use url::{Position, Url};
use dbqueries; use dbqueries;
use errors::DataError; use errors::DataError;
use models::{EpisodeCleanerQuery, Podcast, Save}; use models::{EpisodeCleanerQuery, Save, Show};
use xdg_dirs::DL_DIR; use xdg_dirs::DL_DIR;
use std::fs; use std::fs;
@ -108,9 +108,9 @@ pub fn url_cleaner(s: &str) -> String {
} }
} }
/// Returns the URI of a Podcast Downloads given it's title. /// Returns the URI of a Show Downloads given it's title.
pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> { pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
// It might be better to make it a hash of the title or the podcast rowid // It might be better to make it a hash of the title or the Show rowid
let download_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title); let download_fold = format!("{}/{}", DL_DIR.to_str().unwrap(), pd_title);
// Create the folder // Create the folder
@ -123,7 +123,7 @@ pub fn get_download_folder(pd_title: &str) -> Result<String, DataError> {
/// Removes all the entries associated with the given show from the database, /// Removes all the entries associated with the given show from the database,
/// and deletes all of the downloaded content. /// and deletes all of the downloaded content.
// TODO: Write Tests // TODO: Write Tests
pub fn delete_show(pd: &Podcast) -> Result<(), DataError> { pub fn delete_show(pd: &Show) -> Result<(), DataError> {
dbqueries::remove_feed(pd)?; dbqueries::remove_feed(pd)?;
info!("{} was removed succesfully.", pd.title()); info!("{} was removed succesfully.", pd.title());

View File

@ -12,7 +12,7 @@ use std::path::Path;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use hammond_data::xdg_dirs::HAMMOND_CACHE; use hammond_data::xdg_dirs::HAMMOND_CACHE;
use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery, Save}; use hammond_data::{EpisodeWidgetQuery, Save, ShowCoverQuery};
// use failure::Error; // use failure::Error;
use errors::DownloadError; use errors::DownloadError;
@ -196,7 +196,7 @@ pub fn get_episode(
Ok(()) Ok(())
} }
pub fn cache_image(pd: &PodcastCoverQuery) -> Result<String, DownloadError> { pub fn cache_image(pd: &ShowCoverQuery) -> Result<String, DownloadError> {
let url = pd let url = pd
.image_uri() .image_uri()
.ok_or_else(|| DownloadError::NoImageLocation)? .ok_or_else(|| DownloadError::NoImageLocation)?

View File

@ -10,7 +10,7 @@ use gtk::prelude::*;
use gtk::SettingsExt as GtkSettingsExt; use gtk::SettingsExt as GtkSettingsExt;
use crossbeam_channel::{unbounded, Receiver, Sender}; use crossbeam_channel::{unbounded, Receiver, Sender};
use hammond_data::Podcast; use hammond_data::Show;
use headerbar::Header; use headerbar::Header;
use settings::{self, WindowGeometry}; use settings::{self, WindowGeometry};
@ -43,7 +43,7 @@ pub enum Action {
RefreshEpisodesView, RefreshEpisodesView,
RefreshEpisodesViewBGR, RefreshEpisodesViewBGR,
RefreshShowsView, RefreshShowsView,
ReplaceWidget(Arc<Podcast>), ReplaceWidget(Arc<Show>),
RefreshWidgetIfSame(i32), RefreshWidgetIfSame(i32),
ShowWidgetAnimated, ShowWidgetAnimated,
ShowShowsAnimated, ShowShowsAnimated,
@ -51,8 +51,8 @@ pub enum Action {
HeaderBarNormal, HeaderBarNormal,
HeaderBarShowUpdateIndicator, HeaderBarShowUpdateIndicator,
HeaderBarHideUpdateIndicator, HeaderBarHideUpdateIndicator,
MarkAllPlayerNotification(Arc<Podcast>), MarkAllPlayerNotification(Arc<Show>),
RemoveShow(Arc<Podcast>), RemoveShow(Arc<Show>),
ErrorNotification(String), ErrorNotification(String),
InitEpisode(i32), InitEpisode(i32),
} }

View File

@ -6,7 +6,7 @@ use crossbeam_channel::Sender;
use failure::Error; use failure::Error;
use hammond_data::dbqueries; use hammond_data::dbqueries;
use hammond_data::Podcast; use hammond_data::Show;
use app::Action; use app::Action;
use widgets::{ShowWidget, ShowsView}; use widgets::{ShowWidget, ShowsView};
@ -89,7 +89,7 @@ impl PopulatedStack {
Ok(()) Ok(())
} }
pub fn replace_widget(&mut self, pd: Arc<Podcast>) -> Result<(), Error> { pub fn replace_widget(&mut self, pd: Arc<Show>) -> Result<(), Error> {
let old = self.show.container.clone(); let old = self.show.container.clone();
// save the ShowWidget vertical scrollabar alignment // save the ShowWidget vertical scrollabar alignment

View File

@ -14,7 +14,7 @@ use failure::Error;
use send_cell::SendCell; use send_cell::SendCell;
use hammond_data::{dbqueries, USER_AGENT}; use hammond_data::{dbqueries, USER_AGENT};
use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery}; use hammond_data::{EpisodeWidgetQuery, ShowCoverQuery};
use app::Action; use app::Action;
use utils::set_image_from_path; use utils::set_image_from_path;
@ -49,7 +49,7 @@ struct PlayerInfo {
impl PlayerInfo { impl PlayerInfo {
// FIXME: create a Diesel Model of the joined episode and podcast query instead // FIXME: create a Diesel Model of the joined episode and podcast query instead
fn init(&self, episode: &EpisodeWidgetQuery, podcast: &PodcastCoverQuery) { fn init(&self, episode: &EpisodeWidgetQuery, podcast: &ShowCoverQuery) {
self.set_cover_image(podcast); self.set_cover_image(podcast);
self.set_show_title(podcast); self.set_show_title(podcast);
self.set_episode_title(episode); self.set_episode_title(episode);
@ -60,12 +60,12 @@ impl PlayerInfo {
self.episode.set_tooltip_text(episode.title()); self.episode.set_tooltip_text(episode.title());
} }
fn set_show_title(&self, show: &PodcastCoverQuery) { fn set_show_title(&self, show: &ShowCoverQuery) {
self.show.set_text(show.title()); self.show.set_text(show.title());
self.show.set_tooltip_text(show.title()); self.show.set_tooltip_text(show.title());
} }
fn set_cover_image(&self, show: &PodcastCoverQuery) { fn set_cover_image(&self, show: &ShowCoverQuery) {
set_image_from_path(&self.cover, show.id(), 34) set_image_from_path(&self.cover, show.id(), 34)
.map_err(|err| error!("Player Cover: {}", err)) .map_err(|err| error!("Player Cover: {}", err))
.ok(); .ok();

View File

@ -11,7 +11,7 @@ use send_cell::SendCell;
use hammond_data::dbqueries; use hammond_data::dbqueries;
use hammond_data::utils::delete_show; use hammond_data::utils::delete_show;
use hammond_data::Podcast; use hammond_data::Show;
use app::Action; use app::Action;
use utils::{self, lazy_load}; use utils::{self, lazy_load};
@ -67,7 +67,7 @@ impl Default for ShowWidget {
} }
impl ShowWidget { impl ShowWidget {
pub fn new(pd: Arc<Podcast>, sender: Sender<Action>) -> Rc<ShowWidget> { pub fn new(pd: Arc<Show>, sender: Sender<Action>) -> Rc<ShowWidget> {
let mut pdw = ShowWidget::default(); let mut pdw = ShowWidget::default();
pdw.init(&pd, &sender); pdw.init(&pd, &sender);
let pdw = Rc::new(pdw); let pdw = Rc::new(pdw);
@ -78,7 +78,7 @@ impl ShowWidget {
pdw pdw
} }
pub fn init(&mut self, pd: &Arc<Podcast>, sender: &Sender<Action>) { pub fn init(&mut self, pd: &Arc<Show>, sender: &Sender<Action>) {
let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/show_widget.ui"); let builder = gtk::Builder::new_from_resource("/org/gnome/Hammond/gtk/show_widget.ui");
self.unsub self.unsub
@ -118,7 +118,7 @@ impl ShowWidget {
} }
/// Set the show cover. /// Set the show cover.
fn set_cover(&self, pd: &Arc<Podcast>) -> Result<(), Error> { fn set_cover(&self, pd: &Arc<Show>) -> Result<(), Error> {
utils::set_image_from_path(&self.cover, pd.id(), 256) utils::set_image_from_path(&self.cover, pd.id(), 256)
} }
@ -143,7 +143,7 @@ impl ShowWidget {
} }
/// Set scrolled window vertical adjustment. /// Set scrolled window vertical adjustment.
fn set_vadjustment(&self, pd: &Arc<Podcast>) -> Result<(), Error> { fn set_vadjustment(&self, pd: &Arc<Show>) -> Result<(), Error> {
let guard = SHOW_WIDGET_VALIGNMENT let guard = SHOW_WIDGET_VALIGNMENT
.lock() .lock()
.map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?; .map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?;
@ -174,7 +174,7 @@ impl ShowWidget {
/// Populate the listbox with the shows episodes. /// Populate the listbox with the shows episodes.
fn populate_listbox( fn populate_listbox(
show: &Rc<ShowWidget>, show: &Rc<ShowWidget>,
pd: Arc<Podcast>, pd: Arc<Show>,
sender: Sender<Action>, sender: Sender<Action>,
) -> Result<(), Error> { ) -> Result<(), Error> {
use crossbeam_channel::bounded; use crossbeam_channel::bounded;
@ -223,7 +223,7 @@ fn populate_listbox(
Ok(()) Ok(())
} }
fn on_unsub_button_clicked(pd: Arc<Podcast>, unsub_button: &gtk::Button, sender: &Sender<Action>) { fn on_unsub_button_clicked(pd: Arc<Show>, unsub_button: &gtk::Button, sender: &Sender<Action>) {
// hack to get away without properly checking for none. // hack to get away without properly checking for none.
// if pressed twice would panic. // if pressed twice would panic.
unsub_button.set_sensitive(false); unsub_button.set_sensitive(false);
@ -239,7 +239,7 @@ fn on_unsub_button_clicked(pd: Arc<Podcast>, unsub_button: &gtk::Button, sender:
unsub_button.set_sensitive(true); unsub_button.set_sensitive(true);
} }
fn on_played_button_clicked(pd: Arc<Podcast>, episodes: &gtk::ListBox, sender: &Sender<Action>) { fn on_played_button_clicked(pd: Arc<Show>, episodes: &gtk::ListBox, sender: &Sender<Action>) {
if dim_titles(episodes).is_none() { if dim_titles(episodes).is_none() {
error!("Something went horribly wrong when dimming the titles."); error!("Something went horribly wrong when dimming the titles.");
warn!("RUN WHILE YOU STILL CAN!"); warn!("RUN WHILE YOU STILL CAN!");
@ -248,7 +248,7 @@ fn on_played_button_clicked(pd: Arc<Podcast>, episodes: &gtk::ListBox, sender: &
sender.send(Action::MarkAllPlayerNotification(pd)) sender.send(Action::MarkAllPlayerNotification(pd))
} }
fn mark_all_watched(pd: &Podcast, sender: &Sender<Action>) -> Result<(), Error> { fn mark_all_watched(pd: &Show, sender: &Sender<Action>) -> Result<(), Error> {
dbqueries::update_none_to_played_now(pd)?; dbqueries::update_none_to_played_now(pd)?;
// Not all widgets migth have been loaded when the mark_all is hit // Not all widgets migth have been loaded when the mark_all is hit
// So we will need to refresh again after it's done. // So we will need to refresh again after it's done.
@ -257,7 +257,7 @@ fn mark_all_watched(pd: &Podcast, sender: &Sender<Action>) -> Result<(), Error>
Ok(()) Ok(())
} }
pub fn mark_all_notif(pd: Arc<Podcast>, sender: &Sender<Action>) -> InAppNotification { pub fn mark_all_notif(pd: Arc<Show>, sender: &Sender<Action>) -> InAppNotification {
let id = pd.id(); let id = pd.id();
let callback = clone!(sender => move || { let callback = clone!(sender => move || {
mark_all_watched(&pd, &sender) mark_all_watched(&pd, &sender)
@ -271,7 +271,7 @@ pub fn mark_all_notif(pd: Arc<Podcast>, sender: &Sender<Action>) -> InAppNotific
InAppNotification::new(text, callback, undo_callback, UndoState::Shown) InAppNotification::new(text, callback, undo_callback, UndoState::Shown)
} }
pub fn remove_show_notif(pd: Arc<Podcast>, sender: Sender<Action>) -> InAppNotification { pub fn remove_show_notif(pd: Arc<Show>, sender: Sender<Action>) -> InAppNotification {
let text = format!("Unsubscribed from {}", pd.title()); let text = format!("Unsubscribed from {}", pd.title());
utils::ignore_show(pd.id()) utils::ignore_show(pd.id())

View File

@ -6,7 +6,7 @@ use failure::Error;
use send_cell::SendCell; use send_cell::SendCell;
use hammond_data::dbqueries; use hammond_data::dbqueries;
use hammond_data::Podcast; use hammond_data::Show;
use app::Action; use app::Action;
use utils::{self, get_ignored_shows, lazy_load, set_image_from_path}; use utils::{self, get_ignored_shows, lazy_load, set_image_from_path};
@ -45,7 +45,7 @@ impl ShowsView {
pub fn new(sender: Sender<Action>) -> Result<Rc<Self>, Error> { pub fn new(sender: Sender<Action>) -> Result<Rc<Self>, Error> {
let pop = Rc::new(ShowsView::default()); let pop = Rc::new(ShowsView::default());
pop.init(sender); pop.init(sender);
// Populate the flowbox with the Podcasts. // Populate the flowbox with the Shows.
populate_flowbox(&pop)?; populate_flowbox(&pop)?;
Ok(pop) Ok(pop)
} }
@ -147,13 +147,13 @@ impl Default for ShowsChild {
} }
impl ShowsChild { impl ShowsChild {
pub fn new(pd: &Podcast) -> ShowsChild { pub fn new(pd: &Show) -> ShowsChild {
let child = ShowsChild::default(); let child = ShowsChild::default();
child.init(pd); child.init(pd);
child child
} }
fn init(&self, pd: &Podcast) { fn init(&self, pd: &Show) {
self.container.set_tooltip_text(pd.title()); self.container.set_tooltip_text(pd.title());
WidgetExt::set_name(&self.child, &pd.id().to_string()); WidgetExt::set_name(&self.child, &pd.id().to_string());