v0.09-backend-no-warnings
This commit is contained in:
1
backend/Cargo.lock
generated
1
backend/Cargo.lock
generated
@@ -421,6 +421,7 @@ dependencies = [
|
|||||||
"axum-extra",
|
"axum-extra",
|
||||||
"booksman-orm",
|
"booksman-orm",
|
||||||
"clap",
|
"clap",
|
||||||
|
"dotenvy",
|
||||||
"entity",
|
"entity",
|
||||||
"error-chain",
|
"error-chain",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ entity = { path = "../entity" }
|
|||||||
axum = "^0.5"
|
axum = "^0.5"
|
||||||
axum-extra = { version = "^0.3", features = ["spa"] }
|
axum-extra = { version = "^0.3", features = ["spa"] }
|
||||||
clap = { version = "^3", features = ["derive"] }
|
clap = { version = "^3", features = ["derive"] }
|
||||||
|
dotenvy = "0.15.0"
|
||||||
error-chain = "0.12.4"
|
error-chain = "0.12.4"
|
||||||
log = "^0.4"
|
log = "^0.4"
|
||||||
reqwest = {version = "0.11.11", features = ["json"]}
|
reqwest = {version = "0.11.11", features = ["json"]}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use axum::{
|
|||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
routing::{get,post},
|
routing::{get,post},
|
||||||
Json, Router,
|
Json, Router,
|
||||||
extract::{Extension, Form, Path, Query},
|
extract::{Extension, Form, Path},
|
||||||
};
|
};
|
||||||
use axum_extra::routing::SpaRouter;
|
use axum_extra::routing::SpaRouter;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
@@ -15,12 +15,13 @@ use tower::ServiceBuilder;
|
|||||||
use tower_http::cors::CorsLayer;
|
use tower_http::cors::CorsLayer;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use booksman_orm::{
|
use booksman_orm::{
|
||||||
sea_orm::{Database, DatabaseConnection, ActiveValue},
|
sea_orm::{Database, DatabaseConnection},
|
||||||
Mutation as MutationCore, Query as QueryCore,
|
Mutation as MutationCore, Query as QueryCore,
|
||||||
|
BookAndMeta,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::iter::Peekable;
|
|
||||||
use ::entity::entities::{book,book_author,book_person,book_place,book_subject,book_time,book_isbn};
|
use ::entity::entities::{book,book_author,book_person,book_place,book_subject,book_time,book_isbn};
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
struct BookUI {
|
struct BookUI {
|
||||||
@@ -118,6 +119,15 @@ pub async fn main() {
|
|||||||
// enable console logging
|
// enable console logging
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
|
||||||
|
dotenvy::dotenv().ok();
|
||||||
|
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
|
||||||
|
|
||||||
|
let conn = Database::connect(db_url)
|
||||||
|
.await
|
||||||
|
.expect("Database connection failed");
|
||||||
|
//Migrator::up(&conn, None).await.unwrap();
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/api/search_openlibrary", get(search_openlibrary))
|
.route("/api/search_openlibrary", get(search_openlibrary))
|
||||||
.route("/api/delete/:id", post(delete_book))
|
.route("/api/delete/:id", post(delete_book))
|
||||||
@@ -125,6 +135,7 @@ pub async fn main() {
|
|||||||
.route("/api/create", post(create_book))
|
.route("/api/create", post(create_book))
|
||||||
.merge(SpaRouter::new("/assets", opt.static_dir))
|
.merge(SpaRouter::new("/assets", opt.static_dir))
|
||||||
.layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))
|
.layer(ServiceBuilder::new().layer(TraceLayer::new_for_http()))
|
||||||
|
.layer(Extension(conn))
|
||||||
.layer(
|
.layer(
|
||||||
// see https://docs.rs/tower-http/latest/tower_http/cors/index.html
|
// see https://docs.rs/tower-http/latest/tower_http/cors/index.html
|
||||||
// for more details
|
// for more details
|
||||||
@@ -207,29 +218,62 @@ async fn list_book(
|
|||||||
let books = QueryCore::find_books_plus_meta_in_page(conn,1,5)
|
let books = QueryCore::find_books_plus_meta_in_page(conn,1,5)
|
||||||
.await
|
.await
|
||||||
.expect("could not list books");
|
.expect("could not list books");
|
||||||
let res: Vec<BookUI> = (books.0).iter()
|
|
||||||
.group_by(|x| (x.id, x.title.clone()) ).into_iter().peekable()
|
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 res: Vec<BookUI> = Vec::with_capacity(5);
|
||||||
|
for (id,group) in data_grouped.into_iter() {
|
||||||
|
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: group.clone().into_iter().clone().map(|u| u.cover).next(),
|
||||||
|
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()),
|
||||||
|
|
||||||
|
};
|
||||||
|
res.push(bookui);
|
||||||
|
}
|
||||||
|
/* let mut res: Vec<BookUI> = (books.0).iter()
|
||||||
|
.group_by(|x| (x.id, x.title.clone()) ).into_iter()
|
||||||
.map(|((id,title), group )| BookUI{
|
.map(|((id,title), group )| BookUI{
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
open_library_key: group.map( |u| u.open_library_key).peek(),
|
open_library_key: group.map( |u| u.open_library_key.clone()).next(),
|
||||||
edition_count: group.clone().map(|u| u.edition_count).next(),
|
edition_count: group.map(|u| u.edition_count).next(),
|
||||||
first_publish_year: group.clone().map(|u| u.first_publish_year).next(),
|
first_publish_year: group.map(|u| u.first_publish_year).next(),
|
||||||
median_page_count: group.clone().map(|u| u.median_page_count).next(),
|
median_page_count: group.map(|u| u.median_page_count).next(),
|
||||||
goodread_id: group.clone().map(|u| u.goodread_id).next(),
|
goodread_id: group.map(|u| u.goodread_id.clone()).next(),
|
||||||
description: group.clone().map(|u| u.description).next(),
|
description: group.map(|u| u.description.clone()).next(),
|
||||||
cover: group.clone().map(|u| u.cover).next(),
|
cover: group.map(|u| u.cover.clone()).next(),
|
||||||
location: group.clone().map(|u| u.location).next(),
|
location: group.map(|u| u.location.clone()).next(),
|
||||||
time_added: group.clone().map(|u| u.time_added).next(),
|
time_added: group.map(|u| u.time_added.clone()).next(),
|
||||||
rating: group.clone().map(|u| u.rating).next(),
|
rating: group.map(|u| u.rating).next(),
|
||||||
comments: group.clone().map(|u| u.comments).next(),
|
comments: group.map(|u| u.comments.clone()).next(),
|
||||||
author_name: Some(group.map(|u| u.author_name).collect()),
|
author_name: Some(group.map(|u| u.author_name.clone()).collect()),
|
||||||
person: Some(group.map(|u| u.person).collect()),
|
person: Some(group.map(|u| u.person.clone()).collect()),
|
||||||
place: Some(group.map(|u| u.place).collect()),
|
place: Some(group.map(|u| u.place.clone()).collect()),
|
||||||
subject: Some(group.map(|u| u.subject).collect()),
|
subject: Some(group.map(|u| u.subject.clone()).collect()),
|
||||||
time: Some(group.map(|u| u.time).collect()),
|
time: Some(group.map(|u| u.time.clone()).collect()),
|
||||||
isbn: Some(group.map(|u| u.isbn).collect()),
|
isbn: Some(group.map(|u| u.isbn.clone()).collect()),
|
||||||
}).collect();
|
}).collect();
|
||||||
|
*/
|
||||||
return Json(res);
|
return Json(res);
|
||||||
// "success"
|
// "success"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use ::entity::entities::{book,book_author,book_person,book_place,book_subject,bo
|
|||||||
use sea_orm::*;
|
use sea_orm::*;
|
||||||
//use sea_query::Expr;
|
//use sea_query::Expr;
|
||||||
|
|
||||||
#[derive(FromQueryResult)]
|
#[derive(FromQueryResult,Clone)]
|
||||||
pub struct BookAndMeta {
|
pub struct BookAndMeta {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub open_library_key: String,
|
pub open_library_key: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user