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