hammond-data/src/feed.rs api changes.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use diesel::prelude::*;
|
||||
|
||||
use schema::{episode, podcast, source};
|
||||
use models::{Podcast, Source};
|
||||
use models::{Episode, Podcast, Source};
|
||||
use utils::url_cleaner;
|
||||
use errors::*;
|
||||
|
||||
use dbqueries;
|
||||
@@ -17,8 +18,9 @@ pub struct NewSource {
|
||||
|
||||
impl NewSource {
|
||||
pub fn new_with_uri(uri: &str) -> NewSource {
|
||||
let uri = url_cleaner(uri);
|
||||
NewSource {
|
||||
uri: uri.to_string(),
|
||||
uri,
|
||||
last_modified: None,
|
||||
http_etag: None,
|
||||
}
|
||||
@@ -56,15 +58,26 @@ impl NewEpisode {
|
||||
// TODO: Currently using diesel from master git.
|
||||
// Watch out for v0.99.0 beta and change the toml.
|
||||
// TODO: Refactor into batch indexes instead.
|
||||
pub fn into_episode(self) -> Result<Episode> {
|
||||
self.index()?;
|
||||
Ok(dbqueries::get_episode_from_uri(&self.uri.unwrap())?)
|
||||
}
|
||||
|
||||
pub fn index(&self) -> QueryResult<()> {
|
||||
let ep = dbqueries::get_episode_from_uri(&self.uri.clone().unwrap());
|
||||
|
||||
match ep {
|
||||
Ok(foo) => if foo.title() != self.title.as_ref().map(|x| x.as_str())
|
||||
|| foo.published_date() != self.published_date.as_ref().map(|x| x.as_str())
|
||||
{
|
||||
dbqueries::replace_episode(self)?;
|
||||
},
|
||||
Ok(foo) => {
|
||||
if foo.podcast_id() != self.podcast_id {
|
||||
error!("NEP pid: {}, EP pid: {}", self.podcast_id, foo.podcast_id());
|
||||
};
|
||||
|
||||
if foo.title() != self.title.as_ref().map(|x| x.as_str())
|
||||
|| foo.published_date() != self.published_date.as_ref().map(|x| x.as_str())
|
||||
{
|
||||
dbqueries::replace_episode(self)?;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
dbqueries::insert_new_episode(self)?;
|
||||
}
|
||||
@@ -95,9 +108,15 @@ impl NewPodcast {
|
||||
let pd = dbqueries::get_podcast_from_title(&self.title);
|
||||
|
||||
match pd {
|
||||
Ok(foo) => if foo.link() != self.link {
|
||||
dbqueries::replace_podcast(self)?;
|
||||
},
|
||||
Ok(foo) => {
|
||||
if foo.source_id() != self.source_id {
|
||||
error!("NPD sid: {}, PD sid: {}", self.source_id, foo.source_id());
|
||||
};
|
||||
|
||||
if foo.link() != self.link {
|
||||
dbqueries::replace_podcast(self)?;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
dbqueries::insert_new_podcast(self)?;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use database::connection;
|
||||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations)]
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||
#[table_name = "episode"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[belongs_to(Podcast, foreign_key = "podcast_id")]
|
||||
@@ -127,6 +127,10 @@ impl Episode {
|
||||
self.favorite = b
|
||||
}
|
||||
|
||||
pub fn podcast_id(&self) -> i32 {
|
||||
self.podcast_id
|
||||
}
|
||||
|
||||
pub fn save(&self) -> QueryResult<Episode> {
|
||||
let db = connection();
|
||||
let tempdb = db.lock().unwrap();
|
||||
@@ -135,7 +139,7 @@ impl Episode {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations)]
|
||||
#[derive(Queryable, Identifiable, AsChangeset, Associations, PartialEq)]
|
||||
#[belongs_to(Source, foreign_key = "source_id")]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[table_name = "podcast"]
|
||||
@@ -217,7 +221,7 @@ impl Podcast {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset)]
|
||||
#[derive(Queryable, Identifiable, AsChangeset, PartialEq)]
|
||||
#[table_name = "source"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user