Merge serial module into the graph module

This commit is contained in:
Juno Takano 2026-01-13 12:11:51 -03:00
commit 697dcc720d
17 changed files with 421 additions and 332 deletions

View file

@ -3,7 +3,7 @@ use axum::{
http::{Response, StatusCode, header},
};
use crate::{syntax::serial::populate_graph, router::handlers};
use crate::{graph::Graph, router::handlers};
pub(in crate::router::handlers) fn by_code(
code: Option<u16>,
@ -26,7 +26,7 @@ fn make_body(code: Option<u16>, message: Option<&str>) -> String {
let out_code = code.unwrap_or(500);
let out_message = &message.unwrap_or("Unknown error");
let config = populate_graph().meta.config;
let config = Graph::load().meta.config;
context.insert(
"title",

View file

@ -6,7 +6,7 @@ use axum::{
use crate::prelude::*;
use crate::{
router::handlers,
syntax::serial::{Format, populate_graph, serialize_graph},
graph::{Graph, Format},
};
/// # Panics
@ -35,8 +35,8 @@ pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
#[expect(clippy::unused_async)]
pub async fn serial(format: &Format) -> Response<Body> {
let graph = populate_graph();
let body = serialize_graph(format, &graph);
let graph = Graph::load();
let body = Graph::to_serial(&graph, format);
match *format {
Format::TOML => handlers::raw::make_response(

View file

@ -2,10 +2,10 @@ use axum::response::IntoResponse as _;
use axum::{body::Body, extract::Path, http::Response, response::Redirect};
use crate::graph::Edge;
use crate::{syntax::serial::populate_graph, router::handlers, graph::Node};
use crate::{graph::Graph, router::handlers, graph::Node};
pub async fn node(Path(id): Path<String>) -> Response<Body> {
let graph = populate_graph();
let graph = Graph::load();
let result = graph.find_node(&id);
let found = result.node.is_some();
let nodes: Vec<Node> = graph.nodes.clone().into_values().collect();

View file

@ -5,12 +5,15 @@ use axum::{
Form,
};
use crate::{syntax::serial::populate_graph, router::handlers, graph::Node};
use crate::{
graph::{Graph, Node},
router::handlers,
};
#[expect(clippy::unused_async)]
pub async fn page(template: &str) -> Response<Body> {
let mut context = tera::Context::default();
let graph = populate_graph();
let graph = Graph::load();
let root_node = graph.get_root().unwrap_or_default();
let nodes: Vec<Node> = graph.nodes.into_values().collect();

View file

@ -103,6 +103,7 @@ fn emergency_wrap(error: &tera::Error) -> String {
#[cfg(test)]
mod tests {
use crate::graph::Graph;
use super::*;
@ -154,7 +155,7 @@ mod tests {
let payload = "dBgIw8DnNHxJojiXzu445qUC4UpxwZCy";
let mut context = tera::Context::default();
let node = crate::graph::Node::new(Some(payload.to_string()));
let graph = crate::syntax::serial::populate_graph();
let graph = Graph::load();
context.insert("node", &node);
context
.insert("text", &crate::syntax::content::parse(&node.text, &graph));