diff --git a/backend/src/main.rs b/backend/src/main.rs index cc0148a..c8e8ae1 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -16,19 +16,50 @@ struct Docs { number_of_pages_median: Option, isbn: Option>, cover_i: Option, + cover_url: Option, author_name: Option>, person: Option>, place: Option>, subject: Option>, time: Option>, } - +/* +impl Docs { + fn set_cover_url(&mut self) { + match self.cover_i { + Some(cover_i) => { + self.cover_url = Some(format!( + "https://covers.openlibrary.org/b/id/{}-L.jpg", + (cover_i.unwrap()) + )) + } + None => (), + } + } +} +*/ #[derive(Deserialize, Serialize, Debug)] struct Books { num_found: u32, docs: Vec, } +impl Books { + fn set_all_cover_urls(&mut self) { + for book in self.docs.iter_mut() { + match book.cover_i { + Some(cover_i) => { + book.cover_url = Some(format!( + "https://covers.openlibrary.org/b/id/{}-L.jpg", + cover_i + )) + } + None => (), + } + } + } +} + // Setup the command line interface with clap. #[derive(Parser, Debug)] #[clap(name = "server", about = "A server for our wasm project!")] @@ -101,8 +132,9 @@ async fn hello( //}; let query = format!("https://openlibrary.org/search.json?q={}", search); let res = reqwest::get(query).await.expect("Unable to request"); - let resjson = res.json::().await.expect("Unable to return value"); - + let mut resjson = res.json::().await.expect("Unable to return value"); + resjson.set_all_cover_urls(); + resjson.docs.truncate(10); print!("Search token {:?}\n", search); return Json(resjson); //return "Hello";