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