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"
|
||||
paris = { version = "1.5", features = ["macros"] }
|
||||
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::structures::*;
|
||||
|
||||
use crate::html::render_pages;
|
||||
use argon2::{password_hash::SaltString, Argon2};
|
||||
|
||||
// Endpoint to add a new product
|
||||
#[post("/api/new", data = "<request>")]
|
||||
pub fn new_product(
|
||||
argon2: &State<Argon2>,
|
||||
request: Form<ProductRequest>,
|
||||
) -> Json<Status> {
|
||||
pub fn new_product(argon2: &State<Argon2>, request: Form<ProductRequest>) -> Json<Status> {
|
||||
/* 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<Authenticate>, order: &str, argon2: &State<Argon2
|
|||
|
||||
// Update fields of a product
|
||||
#[post("/api/update", data = "<update>")]
|
||||
pub fn update_product(
|
||||
argon2: &State<Argon2>,
|
||||
update: Form<Update<'_>>,
|
||||
) -> Json<Status> {
|
||||
pub fn update_product(argon2: &State<Argon2>, update: Form<Update<'_>>) -> Json<Status> {
|
||||
if check_password(&update.password, &argon2) {
|
||||
match update.field {
|
||||
// Check what field is being updated
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue