From dad74dc7062fd4e02f970a515da74b212bd1eb16 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 22 Sep 2017 14:10:13 +0300 Subject: [PATCH] Fixed epoch implementation for episode. --- .gitignore | 1 + migrations/2017-09-15-001128_init_schema/up.sql | 2 +- src/feedparser.rs | 10 ++++++---- src/index_feed.rs | 2 +- src/lib.rs | 3 +++ src/models.rs | 6 +++--- src/schema.rs | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 6aa1064..360b42d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target/ **/*.rs.bk Cargo.lock +.vscode diff --git a/migrations/2017-09-15-001128_init_schema/up.sql b/migrations/2017-09-15-001128_init_schema/up.sql index 94877e2..4c20f39 100644 --- a/migrations/2017-09-15-001128_init_schema/up.sql +++ b/migrations/2017-09-15-001128_init_schema/up.sql @@ -12,7 +12,7 @@ CREATE TABLE `episode` ( `local_uri` TEXT, `description` TEXT, `published_date` TEXT , - `epoch` INTEGER, + `epoch` INTEGER NOT NULL DEFAULT 0, `length` INTEGER, `guid` TEXT, `podcast_id` INTEGER NOT NULL diff --git a/src/feedparser.rs b/src/feedparser.rs index 4448adf..3c0a3be 100644 --- a/src/feedparser.rs +++ b/src/feedparser.rs @@ -1,4 +1,5 @@ use rss::{Channel, Item}; +use chrono::DateTime; use models; use errors::*; @@ -46,12 +47,13 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result foo.set_published_date(ep.published_date); foo.set_guid(ep.guid); foo.set_length(ep.length); - foo.set_epoch(ep.length); + foo.set_epoch(ep.epoch); foo.save_changes::(con)?; } Err(_) => { diff --git a/src/lib.rs b/src/lib.rs index 7ffbc57..744ace1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ extern crate diesel_codegen; extern crate xdg; extern crate reqwest; extern crate rss; +extern crate chrono; pub mod cli; pub mod schema; @@ -35,6 +36,7 @@ pub mod errors { use reqwest; use std::io; use rss; + use chrono; use diesel::migrations::RunMigrationsError; use diesel::result; @@ -46,6 +48,7 @@ pub mod errors { MigrationError(RunMigrationsError); RSSError(rss::Error); DieselResultError(result::Error); + ChronoError(chrono::ParseError); } } } diff --git a/src/models.rs b/src/models.rs index 58dabdc..2af2075 100644 --- a/src/models.rs +++ b/src/models.rs @@ -19,7 +19,7 @@ pub struct Episode { local_uri: Option, description: Option, published_date: Option, - epoch: Option, + epoch: i32, length: Option, guid: Option, podcast_id: i32, @@ -78,11 +78,11 @@ impl Episode { self.guid = value.map(|x| x.to_string()); } - pub fn epoch(&self) -> Option { + pub fn epoch(&self) -> i32 { self.epoch } - pub fn set_epoch(&mut self, value: Option) { + pub fn set_epoch(&mut self, value: i32) { self.epoch = value; } diff --git a/src/schema.rs b/src/schema.rs index 3cdb9e6..6e99078 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -6,7 +6,7 @@ table! { local_uri -> Nullable, description -> Nullable, published_date -> Nullable, - epoch -> Nullable, + epoch -> Integer, length -> Nullable, guid -> Nullable, podcast_id -> Integer,