Cleanup the id() method mess of the diesel models.

This commit is contained in:
Jordan Petridis
2018-01-13 07:46:56 +02:00
parent 6517956987
commit e4d77a6ba4
15 changed files with 21 additions and 31 deletions
+2 -2
View File
@@ -232,8 +232,8 @@ pub fn remove_feed(pd: &Podcast) -> Result<()> {
con.transaction(|| -> Result<()> {
delete_source(&con, pd.source_id())?;
delete_podcast(&con, *pd.id())?;
delete_podcast_episodes(&con, *pd.id())?;
delete_podcast(&con, pd.id())?;
delete_podcast_episodes(&con, pd.id())?;
info!("Feed removed from the Database.");
Ok(())
})
+2 -3
View File
@@ -4,7 +4,6 @@ use rayon::prelude::*;
use diesel::prelude::*;
use rayon::iter::IntoParallelIterator;
use diesel::associations::Identifiable;
use rss;
use dbqueries;
@@ -75,7 +74,7 @@ impl Feed {
let items = self.channel.items();
let new_episodes: Vec<_> = items
.par_iter()
.filter_map(|item| parser::new_episode(item, *pd.id()).ok())
.filter_map(|item| parser::new_episode(item, pd.id()).ok())
.collect();
new_episodes
@@ -203,7 +202,7 @@ mod tests {
let feed = fs::File::open(path).unwrap();
// parse it into a channel
let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap();
Feed::from_channel_source(chan, *s.id())
Feed::from_channel_source(chan, s.id())
})
.collect();
+1 -1
View File
@@ -113,7 +113,7 @@ impl NewPodcast {
if (foo.link() != self.link) || (foo.title() != self.title)
|| (foo.image_uri() != self.image_uri.as_ref().map(|x| x.as_str()))
{
self.update(&con, *foo.id())?;
self.update(&con, foo.id())?;
}
}
Err(_) => {
+12 -2
View File
@@ -451,6 +451,11 @@ pub struct Podcast {
}
impl Podcast {
/// Get the Feed `id`.
pub fn id(&self) -> i32 {
self.id
}
/// Get the Feed `title`.
pub fn title(&self) -> &str {
&self.title
@@ -551,7 +556,7 @@ pub struct PodcastCoverQuery {
impl From<Podcast> for PodcastCoverQuery {
fn from(p: Podcast) -> PodcastCoverQuery {
PodcastCoverQuery {
id: *p.id(),
id: p.id(),
title: p.title,
image_uri: p.image_uri,
}
@@ -592,6 +597,11 @@ pub struct Source {
}
impl<'a> Source {
/// Get the source `id` column.
pub fn id(&self) -> i32 {
self.id
}
/// Represents the location(usually url) of the Feed xml file.
pub fn uri(&self) -> &str {
&self.uri
@@ -739,7 +749,7 @@ impl<'a> Source {
client: &'a mut Client<HttpsConnector<HttpConnector>>,
ignore_etags: bool,
) -> Box<Future<Item = Feed, Error = hyper::Error> + 'a> {
let id = *self.id();
let id = self.id();
let feed = request_constructor(&self, client, ignore_etags)
.map(move |res| {
println!("Status: {}", res.status());