Define a new Diesel Model for PodcastCover querries.
Define new Diesel Model and impl From<Podcast> trait, Change the signature of downloader::cache_image function, Change and merge hammond-gtk::utils::get_pixbuf_from_path functions.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use diesel::prelude::*;
|
||||
use diesel;
|
||||
use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, Source};
|
||||
use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source};
|
||||
use chrono::prelude::*;
|
||||
use errors::*;
|
||||
|
||||
@@ -114,6 +114,17 @@ pub fn get_podcast_from_id(pid: i32) -> Result<Podcast> {
|
||||
Ok(podcast.filter(id.eq(pid)).get_result::<Podcast>(&*con)?)
|
||||
}
|
||||
|
||||
pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery> {
|
||||
use schema::podcast::dsl::*;
|
||||
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
Ok(podcast
|
||||
.select((id, title, image_uri))
|
||||
.filter(id.eq(pid))
|
||||
.get_result::<PodcastCoverQuery>(&*con)?)
|
||||
}
|
||||
|
||||
pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>> {
|
||||
use schema::episode::dsl::*;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ pub(crate) mod models;
|
||||
mod parser;
|
||||
mod schema;
|
||||
|
||||
pub use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, Source};
|
||||
pub use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source};
|
||||
|
||||
/// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths.
|
||||
#[allow(missing_debug_implementations)]
|
||||
|
||||
@@ -427,6 +427,39 @@ impl Podcast {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, Clone)]
|
||||
/// Diesel Model of the podcast cover query.
|
||||
/// Used for fetching information about a Podcast's cover.
|
||||
pub struct PodcastCoverQuery {
|
||||
id: i32,
|
||||
title: String,
|
||||
image_uri: Option<String>,
|
||||
}
|
||||
|
||||
impl From<Podcast> for PodcastCoverQuery {
|
||||
fn from(p: Podcast) -> PodcastCoverQuery {
|
||||
PodcastCoverQuery {
|
||||
id: *p.id(),
|
||||
title: p.title,
|
||||
image_uri: p.image_uri,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PodcastCoverQuery {
|
||||
/// Get the Feed `title`.
|
||||
pub fn title(&self) -> &str {
|
||||
&self.title
|
||||
}
|
||||
|
||||
/// Get the `image_uri`.
|
||||
///
|
||||
/// Represents the uri(url usually) that the Feed cover image is located at.
|
||||
pub fn image_uri(&self) -> Option<&str> {
|
||||
self.image_uri.as_ref().map(|s| s.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, AsChangeset, PartialEq)]
|
||||
#[table_name = "source"]
|
||||
#[changeset_options(treat_none_as_null = "true")]
|
||||
|
||||
Reference in New Issue
Block a user