Skip to content

Commit

Permalink
Added non working query.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 committed Aug 24, 2023
1 parent db6677b commit 6280976
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/controllers/websocket_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pub async fn start_connection(
Ok(resp)
}

#[derive(Deserialize, Serialize)]
struct RSSQuery {
top: Option<i32>
}

#[utoipa::path(
context_path = "/api/v1",
responses(
Expand All @@ -40,14 +45,29 @@ responses(
pub async fn get_rss_feed(
podcast_episode_service: Data<Mutex<PodcastEpisodeService>>,
db: Data<DbPool>, env: Data<Mutex<EnvironmentService>>,
query: Option<web::Query<RSSQuery>>,
) -> Result<HttpResponse, CustomError> {
let env = env.lock().ignore_poison();
let mut podcast_service = podcast_episode_service
.lock()
.ignore_poison();
let downloaded_episodes = podcast_service
.find_all_downloaded_podcast_episodes(&mut db.get()
.unwrap(), env.clone())?;
let downloaded_episodes;

match query {
Some(q) => {
downloaded_episodes = podcast_service
.find_all_downloaded_podcast_episodes(&mut db.get()
.unwrap(), env.clone())?
.into_iter()
.take(q.top.unwrap_or(10) as usize)
.collect::<Vec<PodcastEpisode>>();
},
None => {
downloaded_episodes = podcast_service
.find_all_downloaded_podcast_episodes(&mut db.get()
.unwrap(), env.clone())?;
}
}

let server_url = env.get_server_url();

Expand Down
28 changes: 27 additions & 1 deletion src/models/podcast_episode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::dbconfig::schema::*;
use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use diesel::prelude::{Queryable, Identifiable, Selectable, QueryableByName};
use diesel::{BoolExpressionMethods, delete, insert_into, OptionalExtension, RunQueryDsl, TextExpressionMethods};
use diesel::{BoolExpressionMethods, delete, insert_into, JoinOnDsl, NullableExpressionMethods, OptionalExtension, RunQueryDsl, TextExpressionMethods};

Check failure on line 4 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

unused import: `NullableExpressionMethods`

Check warning on line 4 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

unused import: `NullableExpressionMethods`
use diesel::dsl::sql;
use utoipa::ToSchema;
use diesel::sql_types::{Integer, Text, Nullable, Timestamp, Bool};
Expand Down Expand Up @@ -406,4 +406,30 @@ impl PodcastEpisode{
.execute(conn)
.map_err(map_db_error)
}

pub fn get_podcast_episodes_by_podcast_to_k(conn: &mut DbConnection, top_k: i32){
use crate::dbconfig::schema::podcast_episodes::dsl::*;
use crate::dbconfig::schema::podcast_episodes::dsl::podcast_id as podcast_id_column;
use crate::dbconfig::schema::podcast_episodes as p_episode;
use crate::dbconfig::schema::podcasts::dsl::id as p_id;
use crate::dbconfig::schema::podcasts as podcast_1;

let (podcast_episode1, podcast_episode2) = diesel::alias!(p_episode as p1,
p_episode as p2);

let (podcast_in_table) = diesel::alias!(podcast_1 as p1);

Check failure on line 420 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

unnecessary parentheses around pattern

Check warning on line 420 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

unnecessary parentheses around pattern

let result = podcast_episode1
.inner_join(podcast_episode1.on(podcast_episode1.field(podcast_id).eq

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<Once as Plus<Once>>::Output == Once`

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<Join<Alias<p1>, Alias<p1>, Inner> as AppearsInFromClause<Alias<p1>>>::Count == Once`

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<Join<Alias<p1>, Alias<p1>, Inner> as AppearsInFromClause<Alias<p1>>>::Count == Once`

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<Once as Plus<Once>>::Output == Once`

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<Join<Alias<p1>, Alias<p1>, Inner> as AppearsInFromClause<Alias<p1>>>::Count == Once`

Check failure on line 423 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<Join<Alias<p1>, Alias<p1>, Inner> as AppearsInFromClause<Alias<p1>>>::Count == Once`
(podcast_in_table.field(p_id))))
.filter(podcast_episode1.field(date_of_recording).eq_any(

Check failure on line 425 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

the method `filter` exists for struct `SelectStatement<FromClause<JoinOn<Join<Alias<p1>, Alias<p1>, Inner>, Grouped<Eq<..., ...>>>>>`, but its trait bounds were not satisfied

Check failure on line 425 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

the method `filter` exists for struct `SelectStatement<FromClause<JoinOn<Join<Alias<p1>, Alias<p1>, Inner>, Grouped<Eq<..., ...>>>>>`, but its trait bounds were not satisfied
podcast_episode2.select(podcast_episode2.field(date_of_recording))
.filter(podcast_episode2.field(podcast_id_column)

Check failure on line 427 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<podcast_id as Column>::Table == table`

Check failure on line 427 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<podcast_id as Column>::Table == table`
.eq(podcast_in_table.field(podcast_id)))

Check failure on line 428 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<podcast_id as Column>::Table == table`

Check failure on line 428 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust lint

type mismatch resolving `<podcast_id as Column>::Table == table`

Check failure on line 428 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<podcast_id as Column>::Table == table`

Check failure on line 428 in src/models/podcast_episode.rs

View workflow job for this annotation

GitHub Actions / Rust project

type mismatch resolving `<podcast_id as Column>::Table == table`
.order(podcast_episode2.field(date_of_recording).desc())
.limit(top_k.into())
))
.load::<(Podcast,PodcastEpisode)>(conn)
.expect("Error loading podcasts");
}
}
7 changes: 7 additions & 0 deletions src/service/podcast_episode_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ impl PodcastEpisodeService {
self.map_rss_podcast_episodes(env, result)
}

pub fn find_all_downloaded_podcast_episodes_with_top_k(&mut self, conn: &mut DbConnection,
env: EnvironmentService, top_k: i32)
-> Result<Vec<PodcastEpisode>, CustomError> {
PodcastEpisode::get_podcast_episodes_by_podcast_to_k(conn, top_k)

Check failure on line 372 in src/service/podcast_episode_service.rs

View workflow job for this annotation

GitHub Actions / Rust lint

mismatched types

Check failure on line 372 in src/service/podcast_episode_service.rs

View workflow job for this annotation

GitHub Actions / Rust project

mismatched types
}


fn map_rss_podcast_episodes(&mut self, env: EnvironmentService, result: Vec<PodcastEpisode>)
-> Result<Vec<PodcastEpisode>, CustomError> {
Ok(result
Expand Down

0 comments on commit 6280976

Please sign in to comment.