Add sequences to search books

This commit is contained in:
2023-05-26 22:38:09 +02:00
parent d3be731556
commit 74deae076e
3 changed files with 19 additions and 2 deletions

View File

@@ -69,7 +69,7 @@ pub struct StartDownloadData {
impl ToString for StartDownloadData { impl ToString for StartDownloadData {
fn to_string(&self) -> String { fn to_string(&self) -> String {
let id = self.id; let StartDownloadData { id } = self;
format!("/d_{id}") format!("/d_{id}")
} }
} }

View File

@@ -153,6 +153,22 @@ impl Format for SearchBook {
"".to_string() "".to_string()
}; };
let sequences = match !self.sequences.is_empty() {
true => {
let formated_sequences: String = self
.sequences
.clone()[..min(5, self.sequences.len())]
.into_iter()
.map(|sequence| sequence.format())
.collect::<Vec<String>>()
.join("\n");
let post_fix = if self.sequences.len() > 5 { "\nи др." } else { "" };
format!("Серии:\n{formated_sequences}{post_fix}\n\n")
}
false => "".to_string(),
};
let translators = if !self.translators.is_empty() { let translators = if !self.translators.is_empty() {
let formated_translators = self let formated_translators = self
.translators .translators
@@ -171,7 +187,7 @@ impl Format for SearchBook {
let download_command = (StartDownloadData { id: self.id }).to_string(); let download_command = (StartDownloadData { id: self.id }).to_string();
let download_links = format!("Скачать:\n📥{download_command}"); let download_links = format!("Скачать:\n📥{download_command}");
format!("{book_title}{annotations}{authors}{translators}{download_links}") format!("{book_title}{annotations}{authors}{translators}{sequences}{download_links}")
} }
} }

View File

@@ -139,6 +139,7 @@ pub struct SearchBook {
pub annotation_exists: bool, pub annotation_exists: bool,
pub authors: Vec<BookAuthor>, pub authors: Vec<BookAuthor>,
pub translators: Vec<BookAuthor>, pub translators: Vec<BookAuthor>,
pub sequences: Vec<Sequence>,
} }
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]