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
14 changed files with 116 additions and 116 deletions
+17 -17
View File
@@ -23,18 +23,18 @@ pub fn get_sources() -> Result<Vec<Source>, DataError> {
.map_err(From::from)
}
pub fn get_podcasts() -> Result<Vec<Podcast>, DataError> {
pub fn get_podcasts() -> Result<Vec<Show>, DataError> {
use schema::shows::dsl::*;
let db = connection();
let con = db.get()?;
shows
.order(title.asc())
.load::<Podcast>(&con)
.load::<Show>(&con)
.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::*;
let db = connection();
let con = db.get()?;
@@ -42,7 +42,7 @@ pub fn get_podcasts_filter(filter_ids: &[i32]) -> Result<Vec<Podcast>, DataError
shows
.order(title.asc())
.filter(id.ne_all(filter_ids))
.load::<Podcast>(&con)
.load::<Show>(&con)
.map_err(From::from)
}
@@ -149,18 +149,18 @@ pub fn get_episodes_widgets_filter_limit(
.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::*;
let db = connection();
let con = db.get()?;
shows
.filter(id.eq(pid))
.get_result::<Podcast>(&con)
.get_result::<Show>(&con)
.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::*;
let db = connection();
let con = db.get()?;
@@ -168,11 +168,11 @@ pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery, DataErro
shows
.select((id, title, image_uri))
.filter(id.eq(pid))
.get_result::<PodcastCoverQuery>(&con)
.get_result::<ShowCoverQuery>(&con)
.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::*;
let db = connection();
let con = db.get()?;
@@ -183,7 +183,7 @@ pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataError> {
.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 con = db.get()?;
@@ -193,7 +193,7 @@ pub fn get_pd_episodes_count(parent: &Podcast) -> Result<i64, DataError> {
.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::*;
let db = connection();
let con = db.get()?;
@@ -209,7 +209,7 @@ pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery
.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::*;
let db = connection();
let con = db.get()?;
@@ -221,7 +221,7 @@ pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>, DataEr
.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::*;
// let db = connection();
@@ -256,14 +256,14 @@ pub fn get_source_from_id(id_: i32) -> Result<Source, DataError> {
.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::*;
let db = connection();
let con = db.get()?;
shows
.filter(source_id.eq(sid))
.get_result::<Podcast>(&con)
.get_result::<Show>(&con)
.map_err(From::from)
}
@@ -295,7 +295,7 @@ pub(crate) fn get_episode_minimal_from_pk(
.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 con = db.get()?;
@@ -400,7 +400,7 @@ pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
.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::*;
let db = connection();
let con = db.get()?;
+6 -6
View File
@@ -9,7 +9,7 @@ use rss;
use dbqueries;
use errors::DataError;
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`
/// that corresponds to the `Source.uri` field.
@@ -31,15 +31,15 @@ impl Feed {
.and_then(move |pd| self.index_channel_items(pd))
}
fn parse_podcast(&self) -> NewPodcast {
NewPodcast::new(&self.channel, self.source_id)
fn parse_podcast(&self) -> NewShow {
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())
}
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());
// Parse the episodes
@@ -204,7 +204,7 @@ mod tests {
let file = fs::File::open(path).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);
}
+1 -1
View File
@@ -81,7 +81,7 @@ pub mod utils;
pub use feed::{Feed, FeedBuilder};
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
// Keep this in sync with Tor-browser releases
+5 -5
View File
@@ -5,14 +5,14 @@ use diesel::SaveChangesDsl;
use database::connection;
use errors::DataError;
use models::{Podcast, Save};
use models::{Save, Show};
use schema::episodes;
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
#[table_name = "episodes"]
#[changeset_options(treat_none_as_null = "true")]
#[primary_key(title, show_id)]
#[belongs_to(Podcast, foreign_key = "show_id")]
#[belongs_to(Show, foreign_key = "show_id")]
#[derive(Debug, Clone)]
/// Diesel Model of the episode table.
pub struct Episode {
@@ -152,7 +152,7 @@ impl Episode {
self.played = value;
}
/// `Podcast` table foreign key.
/// `Show` table foreign key.
pub fn show_id(&self) -> i32 {
self.show_id
}
@@ -292,7 +292,7 @@ impl EpisodeWidgetQuery {
self.played = value;
}
/// `Podcast` table foreign key.
/// `Show` table foreign key.
pub fn show_id(&self) -> i32 {
self.show_id
}
@@ -445,7 +445,7 @@ impl EpisodeMinimal {
self.duration
}
/// `Podcast` table foreign key.
/// `Show` table foreign key.
pub fn show_id(&self) -> i32 {
self.show_id
}
+5 -5
View File
@@ -1,9 +1,9 @@
mod new_episode;
mod new_podcast;
mod new_show;
mod new_source;
mod episode;
mod podcast;
mod show;
mod source;
// use futures::prelude::*;
@@ -11,16 +11,16 @@ mod source;
pub(crate) use self::episode::EpisodeCleanerQuery;
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;
#[cfg(test)]
pub(crate) use self::new_episode::NewEpisodeBuilder;
#[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::podcast::{Podcast, PodcastCoverQuery};
pub use self::show::{Show, ShowCoverQuery};
pub use self::source::Source;
#[derive(Debug, Clone, PartialEq)]
@@ -4,7 +4,7 @@ use diesel::prelude::*;
use rss;
use errors::DataError;
use models::Podcast;
use models::Show;
use models::{Index, Insert, Update};
use schema::shows;
@@ -18,7 +18,7 @@ use utils::url_cleaner;
#[builder(default)]
#[builder(derive(Debug))]
#[builder(setter(into))]
pub(crate) struct NewPodcast {
pub(crate) struct NewShow {
title: String,
link: String,
description: String,
@@ -26,7 +26,7 @@ pub(crate) struct NewPodcast {
source_id: i32,
}
impl Insert<()> for NewPodcast {
impl Insert<()> for NewShow {
type Error = DataError;
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;
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.
// It would make unti testing better too.
impl Index<()> for NewPodcast {
impl Index<()> for NewShow {
type Error = DataError;
fn index(&self) -> Result<(), DataError> {
@@ -81,8 +81,8 @@ impl Index<()> for NewPodcast {
}
}
impl PartialEq<Podcast> for NewPodcast {
fn eq(&self, other: &Podcast) -> bool {
impl PartialEq<Show> for NewShow {
fn eq(&self, other: &Show) -> bool {
(self.link() == other.link())
&& (self.title() == other.title())
&& (self.image_uri() == other.image_uri())
@@ -91,9 +91,9 @@ impl PartialEq<Podcast> for NewPodcast {
}
}
impl NewPodcast {
/// Parses a `rss::Channel` into a `NewPodcast` Struct.
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewPodcast {
impl NewShow {
/// Parses a `rss::Channel` into a `NewShow` Struct.
pub(crate) fn new(chan: &rss::Channel, source_id: i32) -> NewShow {
let title = chan.title().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
let image_uri = itunes_img.or_else(|| chan.image().map(|s| s.url().trim().to_owned()));
NewPodcastBuilder::default()
NewShowBuilder::default()
.title(title)
.description(description)
.link(link)
@@ -122,14 +122,14 @@ impl NewPodcast {
}
// 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()?;
dbqueries::get_podcast_from_source_id(self.source_id).map_err(From::from)
}
}
// Ignore the following geters. They are used in unit tests mainly.
impl NewPodcast {
impl NewShow {
#[allow(dead_code)]
pub(crate) fn source_id(&self) -> i32 {
self.source_id
@@ -160,14 +160,14 @@ mod tests {
use rss::Channel;
use database::truncate_db;
use models::NewPodcastBuilder;
use models::NewShowBuilder;
use std::fs::File;
use std::io::BufReader;
// Pre-built expected NewPodcast structs.
// Pre-built expected NewShow structs.
lazy_static! {
static ref EXPECTED_INTERCEPTED: NewPodcast = {
static ref EXPECTED_INTERCEPTED: NewShow = {
let descr = "The people behind The Intercepts fearless reporting and incisive \
commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and \
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 \
the world we live in.";
NewPodcastBuilder::default()
NewShowBuilder::default()
.title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts")
.description(descr)
@@ -188,12 +188,12 @@ mod tests {
.build()
.unwrap()
};
static ref EXPECTED_LUP: NewPodcast = {
static ref EXPECTED_LUP: NewShow = {
let descr = "An open show powered by community LINUX Unplugged takes the best \
attributes of open collaboration and focuses them into a weekly \
lifestyle show about Linux.";
NewPodcastBuilder::default()
NewShowBuilder::default()
.title("LINUX Unplugged Podcast")
.link("http://www.jupiterbroadcasting.com/")
.description(descr)
@@ -204,7 +204,7 @@ mod tests {
.build()
.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 \
scenes of some of the best investigative journalism from recent years. \
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 \
journalism- then this is the podcast for you.</p>";
NewPodcastBuilder::default()
NewShowBuilder::default()
.title("The Tip Off")
.link("http://www.acast.com/thetipoff")
.description(desc)
@@ -227,7 +227,7 @@ mod tests {
.build()
.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 \
is a gripping noir science fiction thriller in 14 episodes: Forbidden \
love, a crashed UFO, an alien body, and an impossible heist unlike any \
@@ -237,7 +237,7 @@ mod tests {
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
NewPodcastBuilder::default()
NewShowBuilder::default()
.title("Steal the Stars")
.link("http://tor-labs.com/")
.description(descr)
@@ -246,12 +246,12 @@ mod tests {
.build()
.unwrap()
};
static ref EXPECTED_CODE: NewPodcast = {
static ref EXPECTED_CODE: NewShow = {
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, \
David Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam \
Livingston-Gray. Brought to you by @therubyrep.";
NewPodcastBuilder::default()
NewShowBuilder::default()
.title("Greater Than Code")
.link("https://www.greaterthancode.com/")
.description(descr)
@@ -262,8 +262,8 @@ mod tests {
.build()
.unwrap()
};
static ref EXPECTED_ELLINOFRENEIA: NewPodcast = {
NewPodcastBuilder::default()
static ref EXPECTED_ELLINOFRENEIA: NewShow = {
NewShowBuilder::default()
.title("Ελληνοφρένεια")
.link("https://ellinofreneia.sealabs.net/feed.rss")
.description("Ανεπίσημο feed της Ελληνοφρένειας")
@@ -272,8 +272,8 @@ mod tests {
.build()
.unwrap()
};
static ref UPDATED_DESC_INTERCEPTED: NewPodcast = {
NewPodcastBuilder::default()
static ref UPDATED_DESC_INTERCEPTED: NewShow = {
NewShowBuilder::default()
.title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts")
.description("New Description")
@@ -293,7 +293,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").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);
}
@@ -302,7 +302,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").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);
}
@@ -311,7 +311,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").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);
}
@@ -320,7 +320,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").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);
}
@@ -329,7 +329,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").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);
}
@@ -338,7 +338,7 @@ mod tests {
let file = File::open("tests/feeds/2018-03-28-Ellinofreneia.xml").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);
}
@@ -349,7 +349,7 @@ mod tests {
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").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();
let pd = dbqueries::get_podcast_from_source_id(42).unwrap();
@@ -388,14 +388,14 @@ mod tests {
assert!(EXPECTED_INTERCEPTED.index().is_ok());
// Get the podcast
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);
let updated = &*UPDATED_DESC_INTERCEPTED;
// Update the podcast
assert!(updated.index().is_ok());
// Get the new Podcast
// Get the new Show
let new = dbqueries::get_podcast_from_source_id(42).unwrap();
// Assert it's diff from the old one.
assert_ne!(new, old);
@@ -11,7 +11,7 @@ use schema::shows;
#[table_name = "shows"]
#[derive(Debug, Clone)]
/// Diesel Model of the shows table.
pub struct Podcast {
pub struct Show {
id: i32,
title: String,
link: String,
@@ -20,20 +20,20 @@ pub struct Podcast {
source_id: i32,
}
impl Save<Podcast> for Podcast {
impl Save<Show> for Show {
type Error = DataError;
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<Podcast, Self::Error> {
fn save(&self) -> Result<Show, Self::Error> {
let db = connection();
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`.
pub fn id(&self) -> i32 {
self.id
@@ -51,7 +51,7 @@ impl Podcast {
&self.link
}
/// Set the Podcast/Feed `link`.
/// Set the Show/Feed `link`.
pub fn set_link(&mut self, value: &str) {
self.link = value.to_string();
}
@@ -85,17 +85,17 @@ impl Podcast {
}
#[derive(Queryable, Debug, Clone)]
/// Diesel Model of the podcast cover query.
/// Used for fetching information about a Podcast's cover.
pub struct PodcastCoverQuery {
/// Diesel Model of the Show cover query.
/// Used for fetching information about a Show's cover.
pub struct ShowCoverQuery {
id: i32,
title: String,
image_uri: Option<String>,
}
impl From<Podcast> for PodcastCoverQuery {
fn from(p: Podcast) -> PodcastCoverQuery {
PodcastCoverQuery {
impl From<Show> for ShowCoverQuery {
fn from(p: Show) -> ShowCoverQuery {
ShowCoverQuery {
id: p.id(),
title: p.title,
image_uri: p.image_uri,
@@ -103,7 +103,7 @@ impl From<Podcast> for PodcastCoverQuery {
}
}
impl PodcastCoverQuery {
impl ShowCoverQuery {
/// Get the Feed `id`.
pub fn id(&self) -> i32 {
self.id
+4 -4
View File
@@ -7,7 +7,7 @@ use url::{Position, Url};
use dbqueries;
use errors::DataError;
use models::{EpisodeCleanerQuery, Podcast, Save};
use models::{EpisodeCleanerQuery, Save, Show};
use xdg_dirs::DL_DIR;
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> {
// 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);
// 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,
/// and deletes all of the downloaded content.
// TODO: Write Tests
pub fn delete_show(pd: &Podcast) -> Result<(), DataError> {
pub fn delete_show(pd: &Show) -> Result<(), DataError> {
dbqueries::remove_feed(pd)?;
info!("{} was removed succesfully.", pd.title());