* Create a minimalistic toast

* Profile editing (WIP)
This commit is contained in:
Greg Burri 2024-12-04 17:39:56 +01:00
parent 327b2d0a5b
commit 1c79cc890d
25 changed files with 1133 additions and 575 deletions

View file

@ -2,9 +2,10 @@ use std::{net::SocketAddr, path::Path};
use axum::{
extract::{ConnectInfo, FromRef, Request, State},
http::StatusCode,
middleware::{self, Next},
response::{Response, Result},
routing::{get, post, put},
routing::{get, put},
Router,
};
use axum_extra::extract::cookie::CookieJar;
@ -21,8 +22,10 @@ mod consts;
mod data;
mod email;
mod hash;
mod html_templates;
mod model;
mod ron_extractor;
mod ron_utils;
mod services;
mod utils;
@ -44,6 +47,12 @@ impl FromRef<AppState> for db::Connection {
}
}
impl axum::response::IntoResponse for db::DBError {
fn into_response(self) -> Response {
ron_utils::ron_error(StatusCode::INTERNAL_SERVER_ERROR, &self.to_string()).into_response()
}
}
#[cfg(debug_assertions)]
const TRACING_LEVEL: tracing::Level = tracing::Level::DEBUG;
@ -75,7 +84,12 @@ async fn main() {
db_connection,
};
let app = Router::new()
// TODO: Add fallback fo ron_api_routes.
let ron_api_routes = Router::new()
.route("/user/update", put(services::ron::update_user))
.fallback(services::ron::not_found);
let html_routes = Router::new()
.route("/", get(services::home_page))
.route(
"/signup",
@ -99,15 +113,19 @@ async fn main() {
.route("/recipe/view/:id", get(services::view_recipe))
// User.
.route("/user/edit", get(services::edit_user))
// RON API.
.route("/user/set_name", put(services::ron::update_user))
.route_layer(middleware::from_fn(services::ron_error_to_html));
let app = Router::new()
.merge(html_routes)
.nest("/ron-api", ron_api_routes)
.fallback(services::not_found)
.layer(TraceLayer::new_for_http())
.route_layer(middleware::from_fn_with_state(
// FIXME: Should be 'route_layer' but it doesn't work for 'fallback(..)'.
.layer(middleware::from_fn_with_state(
state.clone(),
user_authentication,
))
.nest_service("/static", ServeDir::new("static"))
.fallback(services::not_found)
.with_state(state)
.into_make_service_with_connect_info::<SocketAddr>();