add editing functionality to index page

This commit is contained in:
2021-09-03 14:31:57 +02:00
parent b03af4e833
commit cc39027a80

View File

@@ -196,14 +196,38 @@ async fn index_process(
} }
} }
} else if query.get("edit").is_some() { } else if query.get("edit").is_some() {
let uuid = Uuid::nil(); match query.get("link") {
// TODO: add actuall logic and use proper uuid Some(link) => {
redirect_to_edit_page( // Splitting string and getting uuid, alternatively pretend whole string is uuid
tmpl, let vec: Vec<&str> = link.split("/").collect();
"Entry found in database!".to_string(),
uuid, let mut uuid_str = link.to_string();
REDIRECT_TIMEOUT_S, if vec.len() > 1 {
) uuid_str = match vec.get(vec.len() - 2) {
Some(s) => s.to_string(),
None => link.to_string(),
};
}
match Uuid::parse_str(&uuid_str) {
Ok(uuid) => redirect_to_edit_page(
tmpl,
"Got uuid from submission!".to_string(),
uuid,
REDIRECT_TIMEOUT_S,
),
// TODO: actually redirect back to index page
Err(e) => error_page(tmpl, format!("could not parse uuid: {}", e.to_string())),
}
}
None => {
// TODO: actually redirect back to index page
error_page(
tmpl,
"link attribute not set please enter a link".to_string(),
)
}
}
} else { } else {
error_page(tmpl, "missing create or edit form submission!".to_string()) error_page(tmpl, "missing create or edit form submission!".to_string())
} }