summaryrefslogtreecommitdiff
path: root/dichroism/src/repo/entities/product_form.rs
blob: b3447eb83dc8945e529834a871d9c7d73ba0b0a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::models::*;
use crate::schema::products;

#[derive(Debug, Insertable, AsChangeset)]
#[table_name = "products"]
pub struct ProductForm {
    pub id: i32,
    pub name: String,
    pub description: String,
    pub quantity: i32,
    pub cents: i32,
    pub featured: i32,
    pub photo_set: i32,
    pub category: String,
}

impl From<Product> for ProductForm {
    fn from(p: Product) -> Self {
        Self {
            id: p.id.unwrap_or(-1),
            name: p.name,
            description: p.description,
            quantity: p.quantity,
            cents: p.cents,
            featured: p.featured as i32,
            photo_set: p.photo_set.id.unwrap_or(-1),
            category: p.category,
        }
    }
}