Compare commits
No commits in common. "v2" and "main" have entirely different histories.
12
Cargo.toml
12
Cargo.toml
@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
edition = "2021"
|
|
||||||
name = "web"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
axum = { version = "0.8" }
|
|
||||||
openssl = { version = "0.10", features = ["vendored"] }
|
|
||||||
pipeline-configuration = { git = "ssh://git@github.com/fathom-io/pipeline-calculations.git" }
|
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
|
||||||
serde_json = "1.0.138"
|
|
||||||
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
|
|
||||||
@ -1,2 +1,2 @@
|
|||||||
# 8db6753a26574668b3818ff15cacd180
|
# 76c70f1a3339429bb3704ac0334d79ae
|
||||||
|
|
||||||
|
|||||||
65
src/main.rs
65
src/main.rs
@ -1,65 +0,0 @@
|
|||||||
use axum::http::HeaderMap;
|
|
||||||
use axum::{routing::post, Router};
|
|
||||||
use pipeline_configuration::pipeline_route::{PipelineRoute, Waypoint};
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
use tokio::net::TcpListener;
|
|
||||||
|
|
||||||
async fn hello_world(headers: HeaderMap, body: String) -> String {
|
|
||||||
let env = std::env::vars().collect::<Vec<_>>();
|
|
||||||
let waypoints = vec![
|
|
||||||
Waypoint {
|
|
||||||
latitude: 52.16975830941925,
|
|
||||||
longitude: -104.1288528141576,
|
|
||||||
measure: 0.0,
|
|
||||||
elevation: 540.0,
|
|
||||||
},
|
|
||||||
Waypoint {
|
|
||||||
latitude: 52.20097892887157,
|
|
||||||
longitude: -104.0144102732867,
|
|
||||||
measure: 8563.471,
|
|
||||||
elevation: 540.0,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let route = PipelineRoute::new(waypoints);
|
|
||||||
let start = route.location_of_measure(100.0).unwrap();
|
|
||||||
let args = Args::from_body(&body);
|
|
||||||
format!("Request headers: {headers:?}, request body: {body}, env: {env:?}, start: {start:?}")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() {
|
|
||||||
let router = Router::new().route("/", post(hello_world));
|
|
||||||
|
|
||||||
let addr = SocketAddr::from(([0, 0, 0, 0], 8080));
|
|
||||||
let tcp = TcpListener::bind(&addr).await.unwrap();
|
|
||||||
println!("Ready and listening on {}", addr);
|
|
||||||
axum::serve(tcp, router).await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
|
||||||
struct Args {
|
|
||||||
facilities: Vec<String>,
|
|
||||||
local_data: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Args {
|
|
||||||
fn from_body(body: &str) -> serde_json::Result<Self> {
|
|
||||||
let value: String = serde_json::from_str(body)?;
|
|
||||||
serde_json::from_str(&value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
const INPUT: &str = "\"{\\\"facilities\\\": [\\\"repairs\\\"], \\\"formData\\\": {\\\"facilities\\\": [\\\"repairs\\\"], \\\"localProperties\\\": [\\\"material_grade\\\", \\\"coating_type\\\", \\\"soil_type\\\", \\\"soil_ph\\\"]}, \\\"input\\\": null, \\\"local_data\\\": [\\\"material_grade\\\", \\\"coating_type\\\", \\\"soil_type\\\", \\\"soil_ph\\\"]}\"";
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test() {
|
|
||||||
let env = std::env::vars().collect::<Vec<_>>();
|
|
||||||
|
|
||||||
println!("body: {}, env: {env:?}", INPUT);
|
|
||||||
let args = Args::from_body(INPUT);
|
|
||||||
dbg!(args).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user