diff --git a/Cargo.toml b/Cargo.toml index 5bfeddd..d585aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,3 +23,4 @@ captcha = "0.0.8" #env_logger = "0.9.0" paris = { version = "1.5", features = ["macros"] } tera = "1" +toml = "0.5" diff --git a/src/api.rs b/src/api.rs index ea815f0..060e873 100644 --- a/src/api.rs +++ b/src/api.rs @@ -8,14 +8,12 @@ use crate::authenticate::*; use crate::database::*; use crate::structures::*; +use crate::html::render_pages; use argon2::{password_hash::SaltString, Argon2}; // Endpoint to add a new product #[post("/api/new", data = "")] -pub fn new_product( - argon2: &State, - request: Form, -) -> Json { +pub fn new_product(argon2: &State, request: Form) -> Json { /* Need to rework the password mechanism so it's not stored in plaintext serverside */ if check_password(&request.password, &argon2) { @@ -26,6 +24,7 @@ pub fn new_product( full_name: request.full_name.clone(), price_usd: request.price_usd, stock: request.stock, + class: request.class, }; match register_product(&new_product.short_name, &new_product) { @@ -39,6 +38,8 @@ pub fn new_product( } } + render_pages(); + return Json(Status { // Return a JSON status status: "success".to_string(), @@ -225,10 +226,7 @@ pub fn delete_order(auth: Form, order: &str, argon2: &State, - update: Form>, -) -> Json { +pub fn update_product(argon2: &State, update: Form>) -> Json { if check_password(&update.password, &argon2) { match update.field { // Check what field is being updated diff --git a/src/structures.rs b/src/structures.rs index 60ef5fe..90ea135 100644 --- a/src/structures.rs +++ b/src/structures.rs @@ -36,9 +36,17 @@ pub struct ProductRequest { pub short_name: String, pub price_usd: f64, pub stock: u32, + pub class: ProductClass, pub password: String, } +#[derive(Serialize, Deserialize, Copy, Clone, Debug, FromFormField)] +pub enum ProductClass { + Estrogens, + AntiAndrogens, + Progestogens, +} + // Struct for a stored product #[derive(Clone, Serialize, Deserialize, Debug, FromForm)] pub struct Product { @@ -46,6 +54,7 @@ pub struct Product { pub short_name: String, pub price_usd: f64, pub stock: u32, + pub class: ProductClass, } // User order request