Heavy refactor and extraction of most code to handler submodules
This commit is contained in:
parent
7d87046166
commit
ab6e90b6b8
9 changed files with 313 additions and 277 deletions
29
src/handlers/navigation.rs
Normal file
29
src/handlers/navigation.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use axum::{
|
||||
body::Body,
|
||||
http::{Response},
|
||||
response::Redirect,
|
||||
Form,
|
||||
};
|
||||
|
||||
use crate::{formats::populate_graph, types::Node, handlers};
|
||||
|
||||
pub async fn nexus(template: &str) -> Response<Body> {
|
||||
let mut context = tera::Context::new();
|
||||
let graph = populate_graph();
|
||||
let root_node = graph.get_root().unwrap_or_default();
|
||||
let nodes: Vec<Node> = graph.nodes.into_values().collect();
|
||||
|
||||
context.insert("nodes", &nodes);
|
||||
context.insert("root_node", &root_node);
|
||||
|
||||
handlers::template::by_filename(template, &context, 500, None, false)
|
||||
}
|
||||
|
||||
pub async fn search(Form(query): Form<Query>) -> Redirect {
|
||||
Redirect::permanent(format!("/node/{}", query.node).as_str())
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct Query {
|
||||
node: String,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue