v0.15-WORKINGV1

This commit is contained in:
2022-12-03 22:43:49 +05:30
parent c7c2465a87
commit 9f7731ef42
12 changed files with 504 additions and 147 deletions

1
backend/Cargo.lock generated
View File

@@ -433,6 +433,7 @@ dependencies = [
"axum-extra",
"booksman-orm",
"booksman-search",
"chrono",
"clap",
"dotenvy",
"entity",

View File

@@ -26,6 +26,7 @@ tower-http = { version = "^0.3", features = ["full"] }
tracing = "^0.1"
tracing-subscriber = "^0.3"
itertools = "0.10"
chrono = "0.4"
[dependencies.sea-orm]
version = "^0.9.2" # sea-orm version

View File

@@ -30,6 +30,7 @@ use meilisearch_sdk::client::Client;
use ::entity::entities::{book,book_author,book_person,book_place,book_subject,book_time,book_isbn};
use std::env;
use migration::{Migrator, MigratorTrait};
use chrono::Local;
#[derive(Deserialize, Serialize, Debug, Clone)]
struct BookUI {
@@ -605,7 +606,7 @@ async fn list_search_book(
let mut resbooks: Vec<BookUI> = Vec::with_capacity(24);
for bookmeili in books.into_iter() {
for bookmeili in books.0.into_iter() {
let mut cover = bookmeili.clone().cover;
if cover!="".to_string() {
cover = format!("{}/images/{}",backend_url,cover);
@@ -637,7 +638,7 @@ let mut resbooks: Vec<BookUI> = Vec::with_capacity(24);
}
let res = PaginatedBookUIList{
num_pages: 10,
num_pages: (books.1/24) as u32,
books: resbooks
};
return Json(res);
@@ -668,7 +669,7 @@ async fn create_book(
let img_bytes = reqwest::get(cover.unwrap()).await.unwrap().bytes().await.unwrap();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = temp_cover.split("/").last().unwrap();
let img_id = format!("{}{}",temp_cover.split("/").last().unwrap(),Local::now().format("%Y-%m-%d-%H-%M-%S"));
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
}
@@ -766,7 +767,7 @@ async fn create_book(
median_page_count: doc_sent.median_page_count.unwrap_or(0),
goodread_id: doc_sent.goodread_id.unwrap_or("".to_string()),
description: doc_sent.description.unwrap_or("".to_string()),
cover: doc_sent.cover.unwrap_or("".to_string()),
cover: cover.unwrap_or("".to_string()),
location: doc_sent.location.unwrap_or("".to_string()),
time_added: doc_sent.time_added.unwrap_or("".to_string()),
rating: doc_sent.rating.unwrap_or(0),
@@ -807,7 +808,7 @@ if !doc_sent.cover.is_none() {
//let img_bytes = img_resp.unwrap().bytes();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = temp_cover.split("/").last().unwrap();
let img_id = format!("{}{}",temp_cover.split("/").last().unwrap(),Local::now().format("%Y-%m-%d-%H-%M-%S"));
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
}
@@ -929,7 +930,7 @@ let book: book::Model = book::Model{
median_page_count: doc_sent.median_page_count.unwrap_or(0),
goodread_id: doc_sent.goodread_id.unwrap_or("".to_string()),
description: doc_sent.description.unwrap_or("".to_string()),
cover: doc_sent.cover.unwrap_or("".to_string()),
cover: cover.unwrap_or("".to_string()),
location: doc_sent.location.unwrap_or("".to_string()),
time_added: doc_sent.time_added.unwrap_or("".to_string()),
rating: doc_sent.rating.unwrap_or(0),

View File

@@ -1,4 +1,4 @@
use chrono::DateTime;
//use chrono::DateTime;
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
@@ -36,7 +36,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Book::Comments).string())
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -62,7 +62,7 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -88,7 +88,7 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -114,7 +114,7 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -140,7 +140,7 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -166,7 +166,7 @@ impl MigrationTrait for Migration {
)
.to_owned(),
)
.await;
.await.expect("Migration failed");
manager
.create_table(
@@ -201,22 +201,22 @@ impl MigrationTrait for Migration {
manager
.drop_table(Table::drop().table(Book::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookAuthor::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookPerson::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookPlace::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookSubject::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookTime::Table).to_owned())
.await;
.await.expect("Drop failed");
manager
.drop_table(Table::drop().table(BookISBN::Table).to_owned())
.await

View File

@@ -42,7 +42,7 @@ pub async fn delete_book(bookid: i32, client: &Client) {
}
pub async fn search_book(search: &str, page: usize, client: &Client) -> Result<Vec<BookMeili>, meilisearch_sdk::errors::Error> {
pub async fn search_book(search: &str, page: usize, client: &Client) -> Result<(Vec<BookMeili>, usize), meilisearch_sdk::errors::Error> {
// An index is where the documents are stored.
let books = client.index("books");
let results : SearchResults<BookMeili> = books.search().with_query(search).with_offset((page-1)*24)
@@ -50,7 +50,7 @@ pub async fn search_book(search: &str, page: usize, client: &Client) -> Result<V
let formatted_results : Vec<BookMeili> = (results.hits).iter().map(|r| r.result.clone()).collect();
//.iter()s.map(|r| r.formatted_result.unwrap()).collect();
return Ok(formatted_results);
return Ok((formatted_results, results.estimated_total_hits));
}