Skip to content

Commit

Permalink
feat(podcasts): filter out keywords (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamTV12345 authored Feb 10, 2025
1 parent eabd062 commit acd9fe8
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ testcontainers = { version = "0.23.1" }
testcontainers-modules = { version = "0.11.6", features = ["postgres","blocking"] }
ctor = "0.2.9"
derive_builder = {version = "0.20.2"}
fake = { version = "3.1.0", features = ["chrono"] }
fake = { version = "3.1.0", features = ["chrono", "url"] }
bollard = {version = "*", features = ["rustls", "rustls-native-certs"], default-features = false}
axum-test = "17.2.0"

Expand Down
43 changes: 41 additions & 2 deletions src/models/podcast_dto.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashSet;
use crate::adapters::file::file_handler::FileHandlerType;
use crate::adapters::file::s3_file_handler::S3_BUCKET_CONFIG;
use crate::constants::inner_constants::ENVIRONMENT_SERVICE;
Expand Down Expand Up @@ -48,14 +49,20 @@ impl From<(Podcast, Option<Favorite>, Vec<Tag>)> for PodcastDto {
}
};

let keywords_to_map = value.0.keywords.clone();
let keywords = keywords_to_map
.map(|k| k.split(",").map(|k|k.trim().to_string())
.collect::<HashSet<String>>()
.into_iter().collect::<Vec<_>>().join(","));

PodcastDto {
id: value.0.id,
name: value.0.name.clone(),
directory_id: value.0.directory_id.clone(),
rssfeed: value.0.rssfeed.clone(),
image_url,
language: value.0.language.clone(),
keywords: value.0.keywords.clone(),
keywords,
summary: value.0.summary.clone(),
explicit: value.0.clone().explicit,
last_build_date: value.0.clone().last_build_date,
Expand All @@ -77,14 +84,21 @@ impl From<Podcast> for PodcastDto {
ENVIRONMENT_SERVICE.get_server_url(),
value.image_url
);

let keywords_to_map = value.keywords.clone();
let keywords = keywords_to_map
.map(|k| k.split(",").map(|k|k.trim().to_string())
.collect::<HashSet<String>>()
.into_iter().collect::<Vec<_>>().join(","));

PodcastDto {
id: value.id,
name: value.name.clone(),
directory_id: value.directory_id.clone(),
rssfeed: value.rssfeed.clone(),
image_url,
language: value.language.clone(),
keywords: value.keywords.clone(),
keywords,
summary: value.summary.clone(),
explicit: value.clone().explicit,
last_build_date: value.clone().last_build_date,
Expand All @@ -97,3 +111,28 @@ impl From<Podcast> for PodcastDto {
}
}
}

#[cfg(test)]
pub mod tests {
use crate::models::podcast_dto::PodcastDto;
use crate::models::podcasts::Podcast;
use crate::utils::test_builder::podcast_test_builder::tests::{PodcastTestDataBuilder};

#[test]
pub fn test_podcast_2_keywords() {
let podcast = PodcastTestDataBuilder::default().keywords("keyword1, keyword2, keyword1".to_string())
.build()
.unwrap();
let podcast_dto: PodcastDto = PodcastDto::from(Podcast::from(podcast));
assert_eq!(podcast_dto.keywords.unwrap().split(",").count(), 2);
}

#[test]
pub fn test_podcast_3_keywords() {
let podcast = PodcastTestDataBuilder::default().keywords("keyword1, keyword2, keyword1, keyword2, keyword1, keyword3".to_string())
.build()
.unwrap();
let podcast_dto: PodcastDto = PodcastDto::from(Podcast::from(podcast));
assert_eq!(podcast_dto.keywords.unwrap().split(",").count(), 3);
}
}
1 change: 1 addition & 0 deletions src/utils/test_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod device_test_builder;
pub mod notification_test_builder;
pub mod user_test_builder;
pub mod podcast_test_builder;
9 changes: 2 additions & 7 deletions src/utils/test_builder/notification_test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ pub mod tests {
use fake::faker::chrono::en::Time;
use fake::{Fake, Faker};

#[derive(Builder)]
#[derive(Default, Builder, Debug)]
#[builder(setter(into))]
pub struct NotificationTestDataBuilder {
pub message: String,
pub status: String,
pub created_at: String,
}

impl Default for NotificationTestDataBuilder {
fn default() -> Self {
Self::new()
}
}

impl NotificationTestDataBuilder {
pub fn new() -> NotificationTestDataBuilder {
NotificationTestDataBuilder {
Expand Down
96 changes: 96 additions & 0 deletions src/utils/test_builder/podcast_test_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#[cfg(test)]
pub mod tests {
use derive_builder::Builder;
use fake::Fake;
use fake::Faker;
use fake::faker::lorem::de_de::Word;
use crate::models::podcasts::Podcast;

#[derive(Default, Builder, Debug)]
#[builder(setter(into), default)]
pub struct PodcastTestData {
pub id: i32,
pub name: String,
pub directory_id: String,
pub rssfeed: String,
pub image_url: String,
pub summary: Option<String>,
pub language: Option<String>,
pub explicit: Option<String>,
pub keywords: Option<String>,
pub last_build_date: Option<String>,
pub author: Option<String>,
pub active: bool,
pub original_image_url: String,
pub directory_name: String,
pub download_location: Option<String>
}

impl PodcastTestData {
pub fn new() -> PodcastTestData {
let num_of_keywords: i32 = Faker.fake();
let keywords: String = (0..num_of_keywords).map(|_| Word().fake()).collect::<Vec<String>>().join(",");

PodcastTestData {
id: Faker.fake(),
name: Faker.fake(),
directory_id: Faker.fake(),
rssfeed: Faker.fake(),
image_url: Faker.fake(),
summary: Some(Faker.fake()),
language: Some(Faker.fake()),
explicit: Some(Faker.fake()),
keywords: Some(keywords),
last_build_date: Faker.fake(),
author: Faker.fake(),
active: Faker.fake(),
original_image_url: Faker.fake(),
directory_name: Faker.fake(),
download_location: None,
}
}

pub fn build(self) -> Podcast {
Podcast {
id: self.id,
name: self.name,
directory_id: self.directory_id,
rssfeed: self.rssfeed,
image_url: self.image_url,
summary: self.summary,
author: self.author,
active: self.active,
original_image_url: self.original_image_url,
directory_name: self.directory_name,
download_location: self.download_location,
explicit: self.explicit,
last_build_date: self.last_build_date,
keywords: self.keywords,
language: self.language,
}
}
}

impl From<PodcastTestData> for Podcast {
fn from(value: PodcastTestData) -> Self {
Podcast {
id: value.id,
name: value.name,
directory_id: value.directory_id,
keywords: value.keywords,
language: value.language,
active: value.active,
original_image_url: value.original_image_url,
directory_name: value.directory_name,
download_location: value.download_location,
explicit: value.explicit,
last_build_date: value.last_build_date,
author: value.author,
summary: value.summary,
image_url: value.image_url,
rssfeed: value.rssfeed,
}
}
}

}

0 comments on commit acd9fe8

Please sign in to comment.