From 5feb5cf771d473ff9f55be40169ca5db2bafd268 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sun, 9 Mar 2025 16:07:47 +0100 Subject: Updates in front (RO) --- src/bin/web.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/bin') diff --git a/src/bin/web.rs b/src/bin/web.rs index 4d2938f..eba283c 100644 --- a/src/bin/web.rs +++ b/src/bin/web.rs @@ -4,8 +4,7 @@ use serde::Deserialize; use std::fs; use axum::{ response::{Html, Json}, - extract::Query, - routing::get, + routing::{get, post}, Router, }; @@ -40,11 +39,13 @@ struct SimSpecs { principal: f64, i1: f64, years: u32, + updates: SimUpdates } -async fn api_simulate_get<'a>(Query(specs): Query) -> Json> { - let mut sim = Simulation::new(specs. principal, specs.i1, specs.years); - let updates: SimUpdates = SimUpdates::default(); +async fn api_simulate_post(Json(specs): Json) -> Json { + let mut sim = Simulation::new(specs.principal, specs.i1, specs.years); + let updates: SimUpdates = specs.updates; + // let updates: SimUpdates = SimUpdates::default(); sim.run(updates); Json(sim) } @@ -55,7 +56,7 @@ async fn main() { let app = Router::new() .route("/", get(root_get)) .route("/main.js", get(main_get)) - .route("/api/simulate", get(api_simulate_get)); + .route("/api/simulate", post(api_simulate_post)); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); -- cgit v1.2.3