Recipe edit (WIP): forms to edit groups, steps and ingredients

This commit is contained in:
Greg Burri 2024-12-26 01:39:07 +01:00
parent dd05a673d9
commit 07b7ff425e
25 changed files with 881 additions and 203 deletions

View file

@ -5,7 +5,7 @@ use axum::{
http::StatusCode,
middleware::{self, Next},
response::{Response, Result},
routing::{get, put},
routing::{delete, get, post, put},
Router,
};
use axum_extra::extract::cookie::CookieJar;
@ -101,6 +101,14 @@ async fn main() {
"/recipe/set_is_published",
put(services::ron::set_is_published),
)
.route("/recipe/get_groups", get(services::ron::get_groups))
.route("/recipe/add_group", post(services::ron::add_group))
.route("/recipe/remove_group", delete(services::ron::rm_group))
.route("/recipe/set_group_name", put(services::ron::set_group_name))
.route(
"/recipe/set_group_comment",
put(services::ron::set_group_comment),
)
.fallback(services::ron::not_found);
let fragments_routes = Router::new().route(
@ -183,7 +191,7 @@ async fn get_current_user(
) -> Option<model::User> {
match jar.get(consts::COOKIE_AUTH_TOKEN_NAME) {
Some(token_cookie) => match connection
.authentication(token_cookie.value(), &client_ip, &client_user_agent)
.authentication(token_cookie.value(), client_ip, client_user_agent)
.await
{
Ok(db::user::AuthenticationResult::NotValidToken) => None,
@ -234,12 +242,15 @@ async fn process_args() -> bool {
}
})
.unwrap();
std::fs::copy(&db_path, &db_path_bckup).expect(&format!(
"Unable to make backup of {:?} to {:?}",
&db_path, &db_path_bckup
));
std::fs::remove_file(&db_path)
.expect(&format!("Unable to remove db file: {:?}", &db_path));
std::fs::copy(&db_path, &db_path_bckup).unwrap_or_else(|error| {
panic!(
"Unable to make backup of {:?} to {:?}: {}",
&db_path, &db_path_bckup, error
)
});
std::fs::remove_file(&db_path).unwrap_or_else(|error| {
panic!("Unable to remove db file {:?}: {}", &db_path, error)
});
}
match db::Connection::new().await {