dbquerries: Add get_episodes and get_podcasts querries that can filters.
This commit is contained in:
parent
b2c95e5a73
commit
e9f2ba47f2
@ -33,6 +33,18 @@ pub fn get_podcasts() -> Result<Vec<Podcast>, DataError> {
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_podcasts_filter(ids_list: &[i32]) -> Result<Vec<Podcast>, DataError> {
|
||||||
|
use schema::podcast::dsl::*;
|
||||||
|
let db = connection();
|
||||||
|
let con = db.get()?;
|
||||||
|
|
||||||
|
podcast
|
||||||
|
.order(title.asc())
|
||||||
|
.filter(id.eq_any(ids_list))
|
||||||
|
.load::<Podcast>(&con)
|
||||||
|
.map_err(From::from)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_episodes() -> Result<Vec<Episode>, DataError> {
|
pub fn get_episodes() -> Result<Vec<Episode>, DataError> {
|
||||||
use schema::episode::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
@ -102,7 +114,10 @@ pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>, DataE
|
|||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_episodes_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
pub fn get_episodes_widgets_filter_limit(
|
||||||
|
ids: &[i32],
|
||||||
|
limit: u32,
|
||||||
|
) -> Result<Vec<EpisodeWidgetQuery>, DataError> {
|
||||||
use schema::episode;
|
use schema::episode;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
let con = db.get()?;
|
let con = db.get()?;
|
||||||
@ -120,6 +135,7 @@ pub fn get_episodes_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQu
|
|||||||
episode::podcast_id,
|
episode::podcast_id,
|
||||||
))
|
))
|
||||||
.order(episode::epoch.desc())
|
.order(episode::epoch.desc())
|
||||||
|
.filter(episode::podcast_id.eq_any(ids))
|
||||||
.limit(i64::from(limit))
|
.limit(i64::from(limit))
|
||||||
.load::<EpisodeWidgetQuery>(&con)
|
.load::<EpisodeWidgetQuery>(&con)
|
||||||
.map_err(From::from)
|
.map_err(From::from)
|
||||||
|
|||||||
@ -77,7 +77,7 @@ impl Default for EpisodesView {
|
|||||||
impl EpisodesView {
|
impl EpisodesView {
|
||||||
pub fn new(sender: Sender<Action>) -> Result<EpisodesView, Error> {
|
pub fn new(sender: Sender<Action>) -> Result<EpisodesView, Error> {
|
||||||
let view = EpisodesView::default();
|
let view = EpisodesView::default();
|
||||||
let episodes = dbqueries::get_episodes_widgets_with_limit(50)?;
|
let episodes = dbqueries::get_episodes_widgets_filter_limit(&[], 50)?;
|
||||||
let now_utc = Utc::now();
|
let now_utc = Utc::now();
|
||||||
|
|
||||||
episodes.into_iter().for_each(|ep| {
|
episodes.into_iter().for_each(|ep| {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user