v0.12-searchP1
This commit is contained in:
@@ -269,70 +269,41 @@ async fn list_book(
|
||||
.await
|
||||
.expect("could not list books");
|
||||
|
||||
let mut data_grouped: Vec<(i32,Vec<BookAndMeta>)> = Vec::with_capacity(5);
|
||||
for (key, group) in &books.0.into_iter().group_by(|x| x.id) {
|
||||
data_grouped.push((key, group.collect()));
|
||||
}
|
||||
|
||||
let mut resbooks: Vec<BookUI> = Vec::with_capacity(5);
|
||||
for (id,group) in data_grouped.into_iter() {
|
||||
let mut cover = group.clone().into_iter().clone().map(|u| u.cover).next();
|
||||
|
||||
for bookandmeta in books.0.into_iter() {
|
||||
let mut cover = bookandmeta.clone().book.cover;
|
||||
if !cover.is_none() {
|
||||
cover = Some(format!("http://localhost:8081/images/{}",cover.unwrap()));
|
||||
cover = Some(format!("http://localhost:8081/images/{}",cover.unwrap()));
|
||||
}
|
||||
let bookui = BookUI{
|
||||
id,
|
||||
title: group.clone().into_iter().map( |u| u.title).next().unwrap(),
|
||||
open_library_key: group.clone().into_iter().map( |u| u.open_library_key).next(),
|
||||
edition_count: group.clone().into_iter().clone().map(|u| u.edition_count).next(),
|
||||
first_publish_year: group.clone().into_iter().clone().map(|u| u.first_publish_year).next(),
|
||||
median_page_count: group.clone().into_iter().clone().map(|u| u.median_page_count).next(),
|
||||
goodread_id: group.clone().into_iter().clone().map(|u| u.goodread_id).next(),
|
||||
description: group.clone().into_iter().clone().map(|u| u.description).next(),
|
||||
cover: cover.clone(),
|
||||
location: group.clone().into_iter().clone().map(|u| u.location).next(),
|
||||
time_added: group.clone().into_iter().clone().map(|u| u.time_added).next(),
|
||||
rating: group.clone().into_iter().clone().map(|u| u.rating).next(),
|
||||
comments: group.clone().into_iter().clone().map(|u| u.comments).next(),
|
||||
author_name: Some(group.clone().into_iter().map(|u| u.author_name).collect()),
|
||||
person: Some(group.clone().into_iter().map(|u| u.person).collect()),
|
||||
place: Some(group.clone().into_iter().map(|u| u.place).collect()),
|
||||
subject: Some(group.clone().into_iter().map(|u| u.subject).collect()),
|
||||
time: Some(group.clone().into_iter().map(|u| u.time).collect()),
|
||||
isbn: Some(group.clone().into_iter().map(|u| u.isbn).collect()),
|
||||
|
||||
id: bookandmeta.clone().book.id,
|
||||
title: bookandmeta.clone().book.title,
|
||||
open_library_key: bookandmeta.clone().book.open_library_key,
|
||||
edition_count: bookandmeta.clone().book.edition_count,
|
||||
first_publish_year: bookandmeta.clone().book.first_publish_year,
|
||||
median_page_count: bookandmeta.clone().book.median_page_count,
|
||||
goodread_id: bookandmeta.clone().book.goodread_id,
|
||||
description: bookandmeta.clone().book.description,
|
||||
cover: cover.clone(),
|
||||
location: bookandmeta.clone().book.location,
|
||||
time_added: bookandmeta.clone().book.time_added,
|
||||
rating: bookandmeta.clone().book.rating,
|
||||
comments: bookandmeta.clone().book.comments,
|
||||
author_name: Some(bookandmeta.clone().authors.into_iter().map(|u| u.author_name).collect() ),
|
||||
person: Some(bookandmeta.clone().persons.into_iter().map(|u| u.person).collect()),
|
||||
place: Some(bookandmeta.clone().places.into_iter().map(|u| u.place).collect()),
|
||||
subject: Some(bookandmeta.clone().subjects.into_iter().map(|u| u.subject).collect()),
|
||||
time: Some(bookandmeta.clone().times.into_iter().map(|u| u.time).collect()),
|
||||
isbn: Some(bookandmeta.clone().isbns.into_iter().map(|u| u.isbn).collect()),
|
||||
};
|
||||
resbooks.push(bookui);
|
||||
}
|
||||
|
||||
let res = PaginatedBookUIList{
|
||||
num_pages: books.1 as u32,
|
||||
books: resbooks
|
||||
num_pages: books.1 as u32,
|
||||
books: resbooks
|
||||
};
|
||||
/* let mut res: Vec<BookUI> = (books.0).iter()
|
||||
.group_by(|x| (x.id, x.title.clone()) ).into_iter()
|
||||
.map(|((id,title), group )| BookUI{
|
||||
id,
|
||||
title,
|
||||
open_library_key: group.map( |u| u.open_library_key.clone()).next(),
|
||||
edition_count: group.map(|u| u.edition_count).next(),
|
||||
first_publish_year: group.map(|u| u.first_publish_year).next(),
|
||||
median_page_count: group.map(|u| u.median_page_count).next(),
|
||||
goodread_id: group.map(|u| u.goodread_id.clone()).next(),
|
||||
description: group.map(|u| u.description.clone()).next(),
|
||||
cover: group.map(|u| u.cover.clone()).next(),
|
||||
location: group.map(|u| u.location.clone()).next(),
|
||||
time_added: group.map(|u| u.time_added.clone()).next(),
|
||||
rating: group.map(|u| u.rating).next(),
|
||||
comments: group.map(|u| u.comments.clone()).next(),
|
||||
author_name: Some(group.map(|u| u.author_name.clone()).collect()),
|
||||
person: Some(group.map(|u| u.person.clone()).collect()),
|
||||
place: Some(group.map(|u| u.place.clone()).collect()),
|
||||
subject: Some(group.map(|u| u.subject.clone()).collect()),
|
||||
time: Some(group.map(|u| u.time.clone()).collect()),
|
||||
isbn: Some(group.map(|u| u.isbn.clone()).collect()),
|
||||
}).collect();
|
||||
*/
|
||||
return Json(res);
|
||||
// "success"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user