diff --git a/hammond-data/src/models/episode.rs b/hammond-data/src/models/episode.rs index a60a047..b9232fe 100644 --- a/hammond-data/src/models/episode.rs +++ b/hammond-data/src/models/episode.rs @@ -31,10 +31,12 @@ pub struct Episode { podcast_id: i32, } -impl Save for Episode { +impl Save for Episode { + type Error = DataError; + /// Helper method to easily save/"sync" current state of self to the /// Database. - fn save(&self) -> Result { + fn save(&self) -> Result { let db = connection(); let tempdb = db.get()?; @@ -224,10 +226,12 @@ impl From for EpisodeWidgetQuery { } } -impl Save for EpisodeWidgetQuery { +impl Save for EpisodeWidgetQuery { + type Error = DataError; + /// Helper method to easily save/"sync" current state of self to the /// Database. - fn save(&self) -> Result { + fn save(&self) -> Result { use schema::episode::dsl::*; let db = connection(); @@ -363,10 +367,12 @@ pub struct EpisodeCleanerQuery { played: Option, } -impl Save for EpisodeCleanerQuery { +impl Save for EpisodeCleanerQuery { + type Error = DataError; + /// Helper method to easily save/"sync" current state of self to the /// Database. - fn save(&self) -> Result { + fn save(&self) -> Result { use schema::episode::dsl::*; let db = connection(); diff --git a/hammond-data/src/models/mod.rs b/hammond-data/src/models/mod.rs index 74abd18..59fffb5 100644 --- a/hammond-data/src/models/mod.rs +++ b/hammond-data/src/models/mod.rs @@ -30,22 +30,30 @@ pub enum IndexState { NotChanged, } -pub trait Insert { - fn insert(&self) -> Result; +pub trait Insert { + type Error; + + fn insert(&self) -> Result; } -pub trait Update { - fn update(&self, i32) -> Result; +pub trait Update { + type Error; + + fn update(&self, i32) -> Result; } // This might need to change in the future -pub trait Index: Insert + Update { - fn index(&self) -> Result; +pub trait Index: Insert + Update { + type Error; + + fn index(&self) -> Result>::Error>; } /// FIXME: DOCS -pub trait Save { +pub trait Save { + /// The Error type to be returned. + type Error; /// Helper method to easily save/"sync" current state of a diesel model to /// the Database. - fn save(&self) -> Result; + fn save(&self) -> Result; } diff --git a/hammond-data/src/models/new_episode.rs b/hammond-data/src/models/new_episode.rs index ea9d81f..d41371b 100644 --- a/hammond-data/src/models/new_episode.rs +++ b/hammond-data/src/models/new_episode.rs @@ -43,7 +43,9 @@ impl From for NewEpisode { } } -impl Insert<(), DataError> for NewEpisode { +impl Insert<()> for NewEpisode { + type Error = DataError; + fn insert(&self) -> Result<(), DataError> { use schema::episode::dsl::*; let db = connection(); @@ -58,7 +60,9 @@ impl Insert<(), DataError> for NewEpisode { } } -impl Update<(), DataError> for NewEpisode { +impl Update<()> for NewEpisode { + type Error = DataError; + fn update(&self, episode_id: i32) -> Result<(), DataError> { use schema::episode::dsl::*; let db = connection(); @@ -73,7 +77,9 @@ impl Update<(), DataError> for NewEpisode { } } -impl Index<(), DataError> for NewEpisode { +impl Index<()> for NewEpisode { + type Error = DataError; + // Does not update the episode description if it's the only thing that has // changed. fn index(&self) -> Result<(), DataError> { diff --git a/hammond-data/src/models/new_podcast.rs b/hammond-data/src/models/new_podcast.rs index dd019e6..2bf727b 100644 --- a/hammond-data/src/models/new_podcast.rs +++ b/hammond-data/src/models/new_podcast.rs @@ -26,8 +26,10 @@ pub(crate) struct NewPodcast { source_id: i32, } -impl Insert<(), DataError> for NewPodcast { - fn insert(&self) -> Result<(), DataError> { +impl Insert<()> for NewPodcast { + type Error = DataError; + + fn insert(&self) -> Result<(), Self::Error> { use schema::podcast::dsl::*; let db = connection(); let con = db.get()?; @@ -40,8 +42,10 @@ impl Insert<(), DataError> for NewPodcast { } } -impl Update<(), DataError> for NewPodcast { - fn update(&self, podcast_id: i32) -> Result<(), DataError> { +impl Update<()> for NewPodcast { + type Error = DataError; + + fn update(&self, podcast_id: i32) -> Result<(), Self::Error> { use schema::podcast::dsl::*; let db = connection(); let con = db.get()?; @@ -57,7 +61,9 @@ impl Update<(), DataError> for NewPodcast { // TODO: Maybe return an Enum Instead. // It would make unti testing better too. -impl Index<(), DataError> for NewPodcast { +impl Index<()> for NewPodcast { + type Error = DataError; + fn index(&self) -> Result<(), DataError> { let exists = dbqueries::podcast_exists(self.source_id)?; diff --git a/hammond-data/src/models/podcast.rs b/hammond-data/src/models/podcast.rs index 1ecb43a..a0090aa 100644 --- a/hammond-data/src/models/podcast.rs +++ b/hammond-data/src/models/podcast.rs @@ -25,10 +25,12 @@ pub struct Podcast { source_id: i32, } -impl Save for Podcast { +impl Save for Podcast { + type Error = DataError; + /// Helper method to easily save/"sync" current state of self to the /// Database. - fn save(&self) -> Result { + fn save(&self) -> Result { let db = connection(); let tempdb = db.get()?; diff --git a/hammond-data/src/models/source.rs b/hammond-data/src/models/source.rs index 040cd10..f751522 100644 --- a/hammond-data/src/models/source.rs +++ b/hammond-data/src/models/source.rs @@ -34,10 +34,12 @@ pub struct Source { http_etag: Option, } -impl Save for Source { +impl Save for Source { + type Error = DataError; + /// Helper method to easily save/"sync" current state of self to the /// Database. - fn save(&self) -> Result { + fn save(&self) -> Result { let db = connection(); let con = db.get()?;