Cleanup the id() method mess of the diesel models.
This commit is contained in:
parent
6517956987
commit
e4d77a6ba4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -559,7 +559,6 @@ dependencies = [
|
||||
name = "hammond-downloader"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hammond-data 0.1.0",
|
||||
@ -575,7 +574,6 @@ name = "hammond-gtk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gdk-pixbuf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@ -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(())
|
||||
})
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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(_) => {
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -13,9 +13,5 @@ reqwest = "0.8.2"
|
||||
tempdir = "0.3.5"
|
||||
glob = "0.2.11"
|
||||
|
||||
[dependencies.diesel]
|
||||
features = ["sqlite"]
|
||||
version = "1.0.0"
|
||||
|
||||
[dependencies.hammond-data]
|
||||
path = "../hammond-data"
|
||||
|
||||
@ -219,7 +219,6 @@ mod tests {
|
||||
use hammond_data::Source;
|
||||
use hammond_data::feed::index;
|
||||
use hammond_data::dbqueries;
|
||||
use diesel::associations::Identifiable;
|
||||
|
||||
#[test]
|
||||
// This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit
|
||||
@ -231,7 +230,7 @@ mod tests {
|
||||
// Create and index a source
|
||||
let mut source = Source::from_url(url).unwrap();
|
||||
// Copy it's id
|
||||
let sid = source.id().clone();
|
||||
let sid = source.id();
|
||||
|
||||
// Convert Source it into a Feed and index it
|
||||
let feed = source.into_feed(true).unwrap();
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
use diesel::result;
|
||||
use reqwest;
|
||||
use hammond_data;
|
||||
use std::io;
|
||||
@ -7,7 +6,6 @@ error_chain! {
|
||||
foreign_links {
|
||||
ReqError(reqwest::Error);
|
||||
IoError(io::Error);
|
||||
DieselResultError(result::Error);
|
||||
DataError(hammond_data::errors::Error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#![recursion_limit = "1024"]
|
||||
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
extern crate glob;
|
||||
|
||||
@ -21,10 +21,6 @@ rayon = "0.9.0"
|
||||
regex = "0.2.3"
|
||||
send-cell = "0.1.2"
|
||||
|
||||
[dependencies.diesel]
|
||||
features = ["sqlite"]
|
||||
version = "1.0.0"
|
||||
|
||||
[dependencies.gtk]
|
||||
features = ["v3_22"]
|
||||
version = "0.3.0"
|
||||
|
||||
@ -7,7 +7,6 @@ extern crate glib;
|
||||
extern crate gtk;
|
||||
|
||||
extern crate chrono;
|
||||
extern crate diesel;
|
||||
extern crate dissolve;
|
||||
extern crate hammond_data;
|
||||
extern crate hammond_downloader;
|
||||
|
||||
@ -117,7 +117,6 @@ pub fn add(id: i32, directory: &str, sender: Sender<Action>) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use diesel::Identifiable;
|
||||
|
||||
use hammond_data::database;
|
||||
use hammond_data::utils::get_download_folder;
|
||||
@ -141,7 +140,7 @@ mod tests {
|
||||
// Create and index a source
|
||||
let mut source = Source::from_url(url).unwrap();
|
||||
// Copy it's id
|
||||
let sid = source.id().clone();
|
||||
let sid = source.id();
|
||||
|
||||
// Convert Source it into a Feed and index it
|
||||
let feed = source.into_feed(true).unwrap();
|
||||
@ -152,7 +151,7 @@ mod tests {
|
||||
// Get an episode
|
||||
let episode: Episode = {
|
||||
let con = database::connection();
|
||||
dbqueries::get_episode_from_pk(&*con.get().unwrap(), "e000: Hello, world!", *pd.id())
|
||||
dbqueries::get_episode_from_pk(&*con.get().unwrap(), "e000: Hello, world!", pd.id())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
|
||||
@ -70,7 +70,6 @@ mod tests {
|
||||
use hammond_data::Source;
|
||||
use hammond_data::feed::index;
|
||||
use hammond_data::dbqueries;
|
||||
use diesel::associations::Identifiable;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -83,7 +82,7 @@ mod tests {
|
||||
// Create and index a source
|
||||
let mut source = Source::from_url(url).unwrap();
|
||||
// Copy it's id
|
||||
let sid = source.id().clone();
|
||||
let sid = source.id();
|
||||
|
||||
// Convert Source it into a Feed and index it
|
||||
let feed = source.into_feed(true).unwrap();
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use diesel::associations::Identifiable;
|
||||
|
||||
use hammond_data::dbqueries;
|
||||
use hammond_data::Podcast;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use gtk::prelude::*;
|
||||
use gtk;
|
||||
use diesel::Identifiable;
|
||||
use open;
|
||||
use dissolve;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user