Initial Commit

This commit is contained in:
gabatxo1312 2026-01-23 13:56:30 +01:00
commit e8529bdbee
25 changed files with 13519 additions and 0 deletions

17
src/error.rs Normal file
View file

@ -0,0 +1,17 @@
use askama::Template;
use askama_web::WebTemplate;
use axum::response::{IntoResponse, Response};
#[derive(Template, WebTemplate)]
#[template(path = "error.html")]
struct ErrorTemplate {}
pub enum AppStateError {
Error,
}
impl IntoResponse for AppStateError {
fn into_response(self) -> Response {
ErrorTemplate {}.into_response()
}
}

17
src/lib.rs Normal file
View file

@ -0,0 +1,17 @@
use axum::{Router, routing::get};
use static_serve::embed_assets;
mod error;
mod routes;
pub fn build_app() -> Router {
embed_assets!("assets", compress = true);
Router::new()
.route("/", get(routes::book::index))
.route("/books/{id}", get(routes::book::show))
.route("/books/{id}/edit", get(routes::book::edit))
.route("/books/new", get(routes::book::new))
.route("/users", get(routes::user::index))
.nest("/assets", static_router())
}

10
src/main.rs Normal file
View file

@ -0,0 +1,10 @@
use bookforge::build_app;
#[tokio::main(flavor = "current_thread")]
async fn main() {
let app = build_app();
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
let _ = axum::serve(listener, app).await;
}

57
src/routes/book.rs Normal file
View file

@ -0,0 +1,57 @@
use askama::Template;
use askama_web::WebTemplate;
use axum::extract::Path;
use crate::error::AppStateError;
#[derive(Template, WebTemplate)]
#[template(path = "index.html")]
struct BookIndexTemplate {}
pub async fn index() -> Result<impl axum::response::IntoResponse, AppStateError> {
if 0 > 1 {
return Err(AppStateError::Error);
}
Ok(BookIndexTemplate {})
}
#[derive(Template, WebTemplate)]
#[template(path = "books/show.html")]
struct ShowBookTemplate {}
pub async fn show(
Path(_id): Path<i32>,
) -> Result<impl axum::response::IntoResponse, AppStateError> {
if 0 > 1 {
return Err(AppStateError::Error);
}
Ok(ShowBookTemplate {})
}
#[derive(Template, WebTemplate)]
#[template(path = "books/new.html")]
struct NewBookTemplate {}
pub async fn new() -> Result<impl axum::response::IntoResponse, AppStateError> {
if 0 > 1 {
return Err(AppStateError::Error);
}
Ok(NewBookTemplate {})
}
#[derive(Template, WebTemplate)]
#[template(path = "books/edit.html")]
struct EditBookTemplate {}
pub async fn edit(
Path(_id): Path<i32>,
) -> Result<impl axum::response::IntoResponse, AppStateError> {
if 0 > 1 {
return Err(AppStateError::Error);
}
Ok(EditBookTemplate {})
}

2
src/routes/mod.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod book;
pub mod user;

16
src/routes/user.rs Normal file
View file

@ -0,0 +1,16 @@
use askama::Template;
use askama_web::WebTemplate;
use crate::error::AppStateError;
#[derive(Template, WebTemplate)]
#[template(path = "users/index.html")]
struct UsersIndexTemplate {}
pub async fn index() -> Result<impl axum::response::IntoResponse, AppStateError> {
if 0 > 1 {
return Err(AppStateError::Error);
}
Ok(UsersIndexTemplate {})
}