Backend and frontend fixes
This commit is contained in:
@@ -260,6 +260,7 @@ pub async fn main() {
|
||||
.route("/api/update", post(update_book))
|
||||
.route("/api/delete/:id", get(delete_book))
|
||||
.route("/api/authentication_check", get(authentication_check))
|
||||
.route("/api/refresh_search_index", get(refresh_meili_index))
|
||||
.route_layer(RequireAuthorizationLayer::<booksman_orm::AxumUser>::login())
|
||||
.route("/api/list", get(list_book))
|
||||
.route("/api/list_search", get(list_search_book))
|
||||
@@ -713,6 +714,122 @@ async fn delete_book(
|
||||
"success"
|
||||
}
|
||||
|
||||
|
||||
async fn refresh_meili_index(
|
||||
Extension(ref conn): Extension<DatabaseConnection>,
|
||||
Extension(ref meili_client): Extension<Client>,
|
||||
Extension(user): Extension<booksman_orm::AxumUser>,
|
||||
) -> impl IntoResponse {
|
||||
dotenvy::dotenv().ok();
|
||||
let userid = user.id;
|
||||
|
||||
let page: usize = 0;
|
||||
let sort: String = "desc".to_string();
|
||||
let per_page: usize = 12;
|
||||
|
||||
let books = QueryCore::find_books_plus_meta_in_page(conn, page, per_page, userid, sort.clone())
|
||||
.await
|
||||
.expect("could not list books");
|
||||
|
||||
let num_pages = books.1;
|
||||
for pg_idx in 0..num_pages {
|
||||
let books = QueryCore::find_books_plus_meta_in_page(conn, pg_idx.try_into().unwrap(), per_page, userid, sort.clone())
|
||||
.await
|
||||
.expect("could not list books");
|
||||
|
||||
for bookandmeta in books.0.into_iter() {
|
||||
let bookui = BookUI {
|
||||
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: bookandmeta.clone().book.cover,
|
||||
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(),
|
||||
),
|
||||
};
|
||||
|
||||
let book_meili = BookMeili {
|
||||
id: bookui.id,
|
||||
open_library_key: bookui.open_library_key.unwrap_or("".to_string()),
|
||||
title: bookui.title,
|
||||
edition_count: bookui.edition_count.unwrap_or(0),
|
||||
first_publish_year: bookui.first_publish_year.unwrap_or(0),
|
||||
median_page_count: bookui.median_page_count.unwrap_or(0),
|
||||
goodread_id: bookui.goodread_id.unwrap_or("".to_string()),
|
||||
description: bookui.description.unwrap_or("".to_string()),
|
||||
cover: bookui.cover.unwrap_or("".to_string()),
|
||||
location: bookui.location.unwrap_or("".to_string()),
|
||||
time_added: bookui.time_added.unwrap_or("".to_string()),
|
||||
rating: bookui.rating.unwrap_or(0),
|
||||
comments: bookui.comments.unwrap_or("".to_string()),
|
||||
author_name: bookui.author_name.unwrap_or(vec!["".to_string()]),
|
||||
person: bookui.person.unwrap_or(vec!["".to_string()]),
|
||||
place: bookui.place.unwrap_or(vec!["".to_string()]),
|
||||
subject: bookui.subject.unwrap_or(vec!["".to_string()]),
|
||||
time: bookui.time.unwrap_or(vec!["".to_string()]),
|
||||
isbn: bookui.isbn.unwrap_or(vec!["".to_string()]),
|
||||
};
|
||||
booksman_search::create_or_update_book(book_meili, userid, meili_client).await;
|
||||
}
|
||||
}
|
||||
|
||||
"success"
|
||||
}
|
||||
|
||||
async fn list_book(
|
||||
Extension(ref conn): Extension<DatabaseConnection>,
|
||||
axum::extract::Query(params): axum::extract::Query<HashMap<String, String>>,
|
||||
@@ -734,7 +851,11 @@ async fn list_book(
|
||||
for bookandmeta in books.0.into_iter() {
|
||||
let mut cover = bookandmeta.clone().book.cover;
|
||||
if !cover.is_none() {
|
||||
cover = Some(format!("{}/images/{}", backend_url, cover.unwrap()));
|
||||
if cover.clone().unwrap() != "".to_string() {
|
||||
cover = Some(format!("{}/images/{}", backend_url, cover.unwrap()));
|
||||
} else {
|
||||
cover = Some(format!("{}/images/placeholder.jpg", backend_url));
|
||||
}
|
||||
} else {
|
||||
cover = Some(format!("{}/images/placeholder.jpg", backend_url));
|
||||
}
|
||||
@@ -1022,7 +1143,7 @@ async fn create_book(
|
||||
.expect("could not create book");
|
||||
}
|
||||
let book_meili = BookMeili {
|
||||
id: doc_sent.id,
|
||||
id: created_book.last_insert_id,
|
||||
open_library_key: doc_sent.open_library_key.unwrap_or("".to_string()),
|
||||
title: doc_sent.title,
|
||||
edition_count: doc_sent.edition_count.unwrap_or(0),
|
||||
|
||||
Reference in New Issue
Block a user