diff --git a/BookForge.toml b/BookForge.toml index 0ac7cc8..57033f1 100644 --- a/BookForge.toml +++ b/BookForge.toml @@ -1,6 +1,5 @@ database_path = "" locale = "fr" -base_url = "" [listener] port = 8000 diff --git a/locales/en.yml b/locales/en.yml index 5e258e0..2bc8531 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -1,13 +1,12 @@ _version: 1 name: "BookForge" - common: download: Download create: Create edit: Edit delete: Delete next: Next - previous: Previous + previous: Prev actions: Actions search: Search reset: Reset @@ -16,77 +15,54 @@ common: close: Close confirmation: Confirmation are_you_sure: Are you sure? - nav: toggle: Toggle navigation books: Books users: Users - theme: light: Light dark: Dark - user: attributes: name: Name - owner_books: Owned books + owner_books: Owner books borrowed_books: Borrowed books - index: - title_tag: Users list | BookForge title: All Users - button: Add a user - + button: Add User edit: - title_tag: Edit user | BookForge title: Edit button: Edit user - new: - title_tag: New user | BookForge - title: New user - button: Create user - + title: New User + button: Create User book: attributes: title: Title authors: Author(s) description: Description owner: Owner - current_holder: Current holder + current_holder: Current Holder comment: Comment - index: - title_tag: Books list | BookForge title: All Books - new: - title_tag: New book | BookForge title: New Book - button: Create book + button: Create Book button_short: Add book - edit: - title_tag: Edit book | BookForge - title: Edit book - button: Edit book - + title: Edit Book + button: Edit Book show: - title_tag: Details | BookForge - book_details: Book details - user_details: User details - more_informations: More information - + book_details: Book Details + user_details: User Details + more_informations: More Informations footer: - message: Made with love & Fuck fascists! - + message: Made with Love & Fuck a Fascist! error: error_404: - title_tag: Error 404 | BookForge - title: Oops! This page does not exist + title: Oops ! This page does not exist subtitle: 404 NOT FOUND button: Back to home - generic: - title_tag: Error | BookForge title: Oops! An error occurred diff --git a/src/lib.rs b/src/lib.rs index 6c3de23..9c1f01d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,10 @@ use askama::Template; use askama_web::WebTemplate; use axum::{ Router, - extract::State, routing::{get, post}, }; use static_serve::embed_assets; -use crate::routes::router::Router as InternalRouter; use crate::state::AppState; mod migrations; @@ -46,14 +44,8 @@ pub fn build_app(state: AppState) -> Router { #[derive(Template, WebTemplate)] #[template(path = "404.html")] -struct NotFoundTemplate { - pub router: InternalRouter, -} +struct NotFoundTemplate {} -pub async fn error_handler(State(state): State) -> impl axum::response::IntoResponse { - NotFoundTemplate { - router: InternalRouter { - base_path: state.config.base_path, - }, - } +pub async fn error_handler() -> impl axum::response::IntoResponse { + NotFoundTemplate {} } diff --git a/src/routes/book.rs b/src/routes/book.rs index 8d4fa03..124a44f 100644 --- a/src/routes/book.rs +++ b/src/routes/book.rs @@ -13,7 +13,7 @@ use serde::Deserialize; use serde_with::{NoneAsEmptyString, serde_as}; use snafu::prelude::*; -use crate::{models::book::Model as BookModel, routes::router::Router, state::error::CSVSnafu}; +use crate::{models::book::Model as BookModel, state::error::CSVSnafu}; use crate::{models::user::Model as UserModel, state::error::IOSnafu}; use crate::{ @@ -55,7 +55,6 @@ struct BookIndexTemplate { current_page: u64, total_page: u64, base_query: String, - router: Router, } pub async fn index( @@ -74,7 +73,7 @@ pub async fn index( .context(UserSnafu)?; // Get all Book filtered with query - let books_paginate = BookOperator::new(state.clone()) + let books_paginate = BookOperator::new(state) .all_paginate(page, Some(query.clone())) .await .context(BookSnafu)?; @@ -128,9 +127,6 @@ pub async fn index( current_page: books_paginate.current_page, total_page: books_paginate.total_page, base_query, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -140,7 +136,6 @@ struct ShowBookTemplate { book: BookModel, owner: UserModel, current_holder: Option, - router: Router, } pub async fn show( @@ -173,9 +168,6 @@ pub async fn show( book, owner, current_holder, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -208,23 +200,14 @@ pub async fn create( #[template(path = "books/new.html")] struct NewBookTemplate { users: Vec, - router: Router, } pub async fn new( State(state): State, ) -> Result { - let users = UserOperator::new(state.clone()) - .all() - .await - .context(UserSnafu)?; + let users = UserOperator::new(state).all().await.context(UserSnafu)?; - Ok(NewBookTemplate { - users, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(NewBookTemplate { users }) } #[derive(Template, WebTemplate)] @@ -232,7 +215,6 @@ pub async fn new( struct EditBookTemplate { users: Vec, book: BookModel, - router: Router, } pub async fn edit( @@ -243,18 +225,12 @@ pub async fn edit( .all() .await .context(UserSnafu)?; - let book = BookOperator::new(state.clone()) + let book = BookOperator::new(state) .find_by_id(id) .await .context(BookSnafu)?; - Ok(EditBookTemplate { - users, - book, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(EditBookTemplate { users, book }) } pub async fn update( diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 2bbba56..011ff79 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,3 +1,2 @@ pub mod book; -pub mod router; pub mod user; diff --git a/src/routes/router.rs b/src/routes/router.rs deleted file mode 100644 index 52bcd0b..0000000 --- a/src/routes/router.rs +++ /dev/null @@ -1,54 +0,0 @@ -#[derive(Clone)] -pub struct Router { - pub base_path: String, -} - -impl Router { - pub fn assets(&self, path: &str) -> String { - if self.base_path.is_empty() || self.base_path == "/" { - format!("/{}", path) - } else { - format!("{}/{}", self.base_path.trim_end_matches('/'), path) - } - } - - pub fn root_path(&self) -> String { - format!("{}/", &self.base_path) - } - - // BOOKS ROUTES - - pub fn new_book_path(&self) -> String { - format!("{}/books/new", &self.base_path) - } - - pub fn create_book_path(&self) -> String { - format!("{}/books", &self.base_path) - } - - pub fn update_book_path(&self, id: &i32) -> String { - format!("{}/books/{}", &self.base_path, id) - } - - pub fn download_csv_book_path(&self) -> String { - format!("{}/books/download_csv", &self.base_path) - } - - // USERS - - pub fn index_user_path(&self) -> String { - format!("{}/users", &self.base_path) - } - - pub fn new_user_path(&self) -> String { - format!("{}/users/new", &self.base_path) - } - - pub fn create_user_path(&self) -> String { - format!("{}/users", &self.base_path) - } - - pub fn update_user_path(&self, id: &i32) -> String { - format!("{}/users/{}", &self.base_path, id) - } -} diff --git a/src/routes/user.rs b/src/routes/user.rs index 04eed56..e4458eb 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -16,7 +16,6 @@ use crate::{ book::BookOperator, user::{self, UserOperator}, }, - routes::router::Router, state::{ AppState, error::{AppStateError, BookSnafu, UserSnafu}, @@ -28,7 +27,6 @@ use crate::{ struct UsersIndexTemplate { users_with_books_number: Vec, query: IndexQuery, - router: Router, } pub struct UserWithBookNumber { @@ -88,9 +86,6 @@ pub async fn index( Ok(UsersIndexTemplate { users_with_books_number: result, query, - router: Router { - base_path: state.config.base_path, - }, }) } @@ -140,36 +135,24 @@ pub async fn delete( #[template(path = "users/edit.html")] struct EditTemplate { user: user::Model, - router: Router, } pub async fn edit( State(state): State, Path(id): Path, ) -> Result { - let user = UserOperator::new(state.clone()) + let user = UserOperator::new(state) .find_by_id(id) .await .context(UserSnafu)?; - Ok(EditTemplate { - user, - router: Router { - base_path: state.config.base_path, - }, - }) + Ok(EditTemplate { user }) } #[derive(Template, WebTemplate)] #[template(path = "users/new.html")] -struct NewTemplate { - router: Router, -} +struct NewTemplate {} -pub async fn new(State(state): State) -> impl axum::response::IntoResponse { - NewTemplate { - router: Router { - base_path: state.config.base_path, - }, - } +pub async fn new() -> impl axum::response::IntoResponse { + NewTemplate {} } diff --git a/src/state/config.rs b/src/state/config.rs index f137f8a..3686711 100644 --- a/src/state/config.rs +++ b/src/state/config.rs @@ -33,7 +33,6 @@ pub struct AppConfig { #[serde(default = "AppConfig::default_sqlite_path")] pub database_path: Utf8PathBuf, pub locale: String, - pub base_path: String, pub listener: Listener, } @@ -41,7 +40,6 @@ impl Default for AppConfig { fn default() -> Self { AppConfig { database_path: Self::default_sqlite_path(), - base_path: Self::default_base_path(), locale: Self::default_locale(), listener: Listener::default(), } @@ -100,10 +98,6 @@ impl AppConfig { "en".to_string() } - fn default_base_path() -> String { - "".to_string() - } - pub fn default_sqlite_path() -> Utf8PathBuf { Self::config_path().join("db.sqlite") } diff --git a/src/state/error.rs b/src/state/error.rs index 6a031b6..59d8232 100644 --- a/src/state/error.rs +++ b/src/state/error.rs @@ -6,7 +6,6 @@ use snafu::prelude::*; use crate::{ models::{book::BookError, user::UserError}, - routes::router::Router, state::config::ConfigError, }; @@ -48,7 +47,6 @@ pub enum AppStateError { #[template(path = "error.html")] struct ErrorTemplate { state: AppStateErrorContext, - router: Router, } struct AppStateErrorContext { @@ -68,9 +66,6 @@ impl IntoResponse for AppStateError { let error_context = AppStateErrorContext::from(self); ErrorTemplate { state: error_context, - router: Router { - base_path: "".to_string(), - }, } .into_response() } diff --git a/templates/404.html b/templates/404.html index 6f35ef6..e76f185 100644 --- a/templates/404.html +++ b/templates/404.html @@ -8,6 +8,6 @@

{{ t!("error.error_404.title") }}

{{ t!("error.error_404.subtitle") }}

- {{ t!("error.error_404.button") }} + {{ t!("error.error_404.button") }}
{% endblock %} diff --git a/templates/base.html b/templates/base.html index bc0ed7e..8e7f371 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,12 +4,12 @@ {% block title %}{{ t!("name") }}{% endblock %} - - + + - - + + {% block extra_head %}{% endblock extra_head %} @@ -26,7 +26,7 @@ {% endblock %} - - + + diff --git a/templates/books/edit.html b/templates/books/edit.html index f80be6a..ecb8734 100644 --- a/templates/books/edit.html +++ b/templates/books/edit.html @@ -10,7 +10,7 @@ {{ typography::heading(t!("book.edit.title")) }} {% call cards::card() %} -
+
diff --git a/templates/books/new.html b/templates/books/new.html index 30deb91..719c9e4 100644 --- a/templates/books/new.html +++ b/templates/books/new.html @@ -11,7 +11,7 @@ {{ typography::heading(t!("book.new.title")) }} {% call cards::card() %} - + {{ form_helpers::input("title", t!("book.attributes.title"), is_required = true, placeholder = "Ex: La Petite Dernière") }} {{ form_helpers::input("authors", t!("book.attributes.authors"), is_required = true, placeholder = "Ex: Fatima Daas") }} diff --git a/templates/components/dropdown.html b/templates/components/dropdown.html index 7b0e55d..29c0841 100644 --- a/templates/components/dropdown.html +++ b/templates/components/dropdown.html @@ -18,9 +18,9 @@
diff --git a/templates/error.html b/templates/error.html index 09e125b..abc0eee 100644 --- a/templates/error.html +++ b/templates/error.html @@ -12,6 +12,6 @@

{{ error }}

{% endfor %} - {{ t!("error.error_404.button") }} + {{ t!("error.error_404.button") }} {% endblock %} diff --git a/templates/index.html b/templates/index.html index 2701d7b..641f7a7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,7 @@ {% block main %} {% call typography::heading(t!("book.index.title")) %} - + {{ t!("common.download") }} (csv) {% endcall %} @@ -87,7 +87,7 @@ @@ -98,7 +98,7 @@

{{ t!("common.no_result") }}

- + {{ t!("book.new.button_short") }}
@@ -142,19 +142,19 @@ diff --git a/templates/layout/footer.html b/templates/layout/footer.html index 3f29c8b..0cafa82 100644 --- a/templates/layout/footer.html +++ b/templates/layout/footer.html @@ -2,4 +2,4 @@

{{ t!("footer.message") }}

- + \ No newline at end of file diff --git a/templates/layout/header.html b/templates/layout/header.html index 114aa1f..dd9ecbc 100644 --- a/templates/layout/header.html +++ b/templates/layout/header.html @@ -1,6 +1,6 @@