v0.13-dockerP3
This commit is contained in:
@@ -91,18 +91,18 @@ struct BookPageOL {
|
||||
description: Option<DescriptionOL>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
struct DescriptionOL {
|
||||
value: Option<String>,
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
struct DescriptionOLValue {
|
||||
value: String,
|
||||
}
|
||||
/*
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(untagged)]
|
||||
enum DescriptionOL {
|
||||
DescriptionValueString{value: String},
|
||||
DescriptionValueString(DescriptionOLValue),
|
||||
DescriptionString(String),
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct BooksManyISBN {
|
||||
#[serde(flatten)]
|
||||
@@ -153,25 +153,46 @@ impl Books {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
async fn set_all_descriptions(&mut self) {
|
||||
for book in self.docs.iter_mut() {
|
||||
let query = format!("https://openlibrary.org/{}.json", book.key);
|
||||
let res = reqwest::get(query).await.expect("Unable to request");
|
||||
let resjson = res.json::<BookPageOL>().await.expect("Unable to return value");
|
||||
let description = resjson.description;
|
||||
match description {
|
||||
Some(description) => {
|
||||
match description.value {
|
||||
Some(value) => book.description = Some(value),
|
||||
None => (),
|
||||
|
||||
if !description.is_none() {
|
||||
if let DescriptionOL::DescriptionString(desc_string) = description.clone().unwrap() {
|
||||
book.description = Some(desc_string);
|
||||
}
|
||||
if let DescriptionOL::DescriptionValueString(desc_val) = description.clone().unwrap() {
|
||||
book.description = Some(desc_val.value);
|
||||
}
|
||||
}
|
||||
None => (),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl BookUI {
|
||||
async fn set_descriptions(&mut self) {
|
||||
|
||||
let query = format!("https://openlibrary.org/{}.json", self.open_library_key.as_ref().unwrap().clone());
|
||||
let res = reqwest::get(query).await.expect("Unable to request");
|
||||
let resjson = res.json::<BookPageOL>().await.expect("Unable to return value");
|
||||
let description = resjson.description;
|
||||
|
||||
if !description.is_none() {
|
||||
if let DescriptionOL::DescriptionString(desc_string) = description.clone().unwrap() {
|
||||
self.description = Some(desc_string);
|
||||
}
|
||||
if let DescriptionOL::DescriptionValueString(desc_val) = description.clone().unwrap() {
|
||||
self.description = Some(desc_val.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
async fn handle_error(_err: io::Error) -> impl IntoResponse {
|
||||
@@ -212,7 +233,6 @@ pub async fn main() {
|
||||
|
||||
|
||||
dotenvy::dotenv().ok();
|
||||
let backend_url = env::var("BACKEND_URL").expect("BACKEND_URL is not set in .env file");
|
||||
let images_dir = env::var("IMAGES_DIR").expect("IMAGES_DIR is not set in .env file");
|
||||
let cors_url = env::var("CORS_URL").expect("CORS_URL is not set in .env file");
|
||||
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
|
||||
@@ -305,38 +325,39 @@ async fn create_by_isbn(
|
||||
goodread_id = goodread_identifier.unwrap().get(0).unwrap().to_string()
|
||||
}
|
||||
}
|
||||
let mut authors_name = Some(vec!["".to_string()]);
|
||||
//let mut authors_name = Some(vec!["".to_string()]);
|
||||
//if !bookfound.unwrap().authors.is_none() {
|
||||
authors_name = Some(bookfound.clone().unwrap().authors.iter().map(|s| s.name.clone()).collect());
|
||||
let authors_name = Some(bookfound.clone().unwrap().authors.iter().map(|s| s.name.clone()).collect());
|
||||
//} else {
|
||||
// authors_name = None
|
||||
//}
|
||||
let mut persons = Some(vec!["".to_string()]);
|
||||
let persons : Option<Vec<String>>;
|
||||
//= Some(vec!["".to_string()]);
|
||||
if !bookfound.unwrap().subject_people.is_none() {
|
||||
persons = Some(bookfound.clone().unwrap().subject_people.clone().unwrap().iter().map(|s| s.name.clone()).collect());
|
||||
} else {
|
||||
persons = None;
|
||||
}
|
||||
let mut places = Some(vec!["".to_string()]);
|
||||
let places : Option<Vec<String>>;
|
||||
if !bookfound.unwrap().subject_places.is_none() {
|
||||
places = Some(bookfound.clone().unwrap().subject_places.clone().unwrap().iter().map(|s| s.name.clone()).collect());
|
||||
} else {
|
||||
places = None;
|
||||
}
|
||||
let mut subjects = Some(vec!["".to_string()]);
|
||||
let subjects : Option<Vec<String>>;
|
||||
if !bookfound.unwrap().subjects.is_none() {
|
||||
subjects = Some(bookfound.clone().unwrap().subjects.clone().unwrap().iter().map(|s| s.name.clone()).collect());
|
||||
} else {
|
||||
subjects = None;
|
||||
}
|
||||
let mut times = Some(vec!["".to_string()]);
|
||||
let times : Option<Vec<String>>;
|
||||
if !bookfound.unwrap().subject_times.is_none() {
|
||||
times = Some(bookfound.clone().unwrap().subject_times.clone().unwrap().iter().map(|s| s.name.clone()).collect());
|
||||
} else {
|
||||
times = None;
|
||||
}
|
||||
|
||||
let doc_sent = BookUI{
|
||||
let mut doc_sent = BookUI{
|
||||
id: 1,
|
||||
open_library_key: Some(bookfound.clone().unwrap().key.clone()),
|
||||
title: bookfound.clone().unwrap().title.clone(),
|
||||
@@ -357,6 +378,7 @@ async fn create_by_isbn(
|
||||
time: times,
|
||||
isbn: Some(vec![isbnstring.split("ISBN:").last().unwrap().to_string()])
|
||||
};
|
||||
doc_sent.set_descriptions().await;
|
||||
let book: book::Model = book::Model{
|
||||
open_library_key: doc_sent.open_library_key.to_owned(),
|
||||
title: (doc_sent.title.to_owned()),
|
||||
@@ -479,7 +501,7 @@ async fn search_openlibrary(
|
||||
let mut resjson = res.json::<Books>().await.expect("Unable to return value");
|
||||
resjson.docs.truncate(12);
|
||||
resjson.set_all_cover_urls();
|
||||
// resjson.set_all_descriptions().await;
|
||||
resjson.set_all_descriptions().await;
|
||||
print!("Search token {:?}\n", search);
|
||||
let mut vec = Vec::with_capacity(12);
|
||||
for i in 0..12 as usize {
|
||||
|
||||
Reference in New Issue
Block a user