Added web ui with templates
This commit is contained in:
parent
d2cb5b3031
commit
90b02eef79
24 changed files with 1403 additions and 78 deletions
|
|
@ -9,6 +9,7 @@ use axum::{
|
|||
Router,
|
||||
};
|
||||
use hyper::StatusCode;
|
||||
use tera::Tera;
|
||||
|
||||
mod routes;
|
||||
mod users;
|
||||
|
|
@ -19,38 +20,56 @@ const DB_URL: &str = "sqlite://sqlite.db";
|
|||
async fn main() {
|
||||
let db = accounters::create_db(DB_URL).await.unwrap();
|
||||
|
||||
let state = AppState { db: Arc::new(db) };
|
||||
let mut tmpls = Tera::new("templates/*").unwrap();
|
||||
tmpls.autoescape_on(vec!["html"]);
|
||||
|
||||
let state = AppState {
|
||||
db: Arc::new(db),
|
||||
tmpls: Arc::new(tmpls),
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(index))
|
||||
.nest(
|
||||
"/",
|
||||
Router::new()
|
||||
.route("/", get(routes::ui::index))
|
||||
.route("/accounts/id/:id", get(routes::ui::account))
|
||||
.route("/rules", get(routes::ui::rules::list))
|
||||
.route("/rules/new", get(routes::ui::rules::new_view))
|
||||
.route("/rules/new", post(routes::ui::rules::new_action))
|
||||
.nest(
|
||||
"/static",
|
||||
Router::new().route("/styles.css", get(routes::static_routes::styles)),
|
||||
),
|
||||
)
|
||||
.nest(
|
||||
"/api/v1",
|
||||
Router::new()
|
||||
.route("/user", post(routes::create_user))
|
||||
.route("/login", post(routes::login))
|
||||
.route("/accounts", post(routes::accounts::account_create))
|
||||
.route("/accounts", get(routes::accounts::account_list))
|
||||
.route("/accounts/id/:id", get(routes::accounts::account_get))
|
||||
.route("/user", post(routes::api::create_user))
|
||||
.route("/login", post(routes::api::login))
|
||||
.route("/accounts", post(routes::api::accounts::account_create))
|
||||
.route("/accounts", get(routes::api::accounts::account_list))
|
||||
.route("/accounts/id/:id", get(routes::api::accounts::account_get))
|
||||
.route(
|
||||
"/accounts/id/:id/transaction",
|
||||
post(routes::transactions::create),
|
||||
post(routes::api::transactions::create),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/transaction",
|
||||
get(routes::transactions::list),
|
||||
get(routes::api::transactions::list),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/update",
|
||||
post(routes::accounts::snapshot_update),
|
||||
post(routes::api::accounts::snapshot_update),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/recategorize",
|
||||
post(routes::accounts::recategorize),
|
||||
post(routes::api::accounts::recategorize),
|
||||
)
|
||||
.route("/categories", post(routes::categories::create))
|
||||
.route("/categories", get(routes::categories::list))
|
||||
.route("/rules", post(routes::rules::create))
|
||||
.route("/rules", get(routes::rules::list)),
|
||||
.route("/categories", post(routes::api::categories::create))
|
||||
.route("/categories", get(routes::api::categories::list))
|
||||
.route("/rules", post(routes::api::rules::create))
|
||||
.route("/rules", get(routes::api::rules::list)),
|
||||
)
|
||||
.with_state(state);
|
||||
|
||||
|
|
@ -64,6 +83,7 @@ async fn main() {
|
|||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
db: Arc<SqlitePool>,
|
||||
tmpls: Arc<Tera>,
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Arc<SqlitePool> {
|
||||
|
|
@ -72,6 +92,12 @@ impl FromRef<AppState> for Arc<SqlitePool> {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for Arc<Tera> {
|
||||
fn from_ref(state: &AppState) -> Arc<Tera> {
|
||||
state.tmpls.clone()
|
||||
}
|
||||
}
|
||||
|
||||
async fn index() -> (StatusCode, String) {
|
||||
(StatusCode::OK, String::from("Hello, World!"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue