Flat file database editor and browser with web interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rocket-inv/src/main.rs

39 lines
1.0 KiB

#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;
#[macro_use] extern crate serde;
//use rocket::request::FromSegments;
//use rocket::http::uri::Segments;
//use rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template;
mod store;
use crate::store::Store;
use rocket::State;
use parking_lot::RwLock;
use rocket::response::Redirect;
use rocket::http::Status;
use rocket::request::Form;
use std::collections::HashMap;
#[get("/")]
fn index(store : State<RwLock<Store>>) -> Template {
let mut context = HashMap::new();
let rg = store.read();
context.insert("records", &rg.parts);
Template::render("index", context)
}
#[post("/add", data="<record>")]
fn add_part(store : State<RwLock<Store>>, record : Form<store::Part>) -> Redirect {
store.write().add(record.into_inner());
Redirect::to(uri!(index))
}
fn main() {
rocket::ignite()
.attach(Template::fairing())
.manage(RwLock::new(Store::new()))
.mount("/", routes![index, add_part]).launch();
}