blob: f23146914b106608a60dba79fe98b365133d5759 (
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
31
|
use crate::models::Product;
#[derive(Debug, Deserialize)]
pub struct ProductPatch {
pub id: i32,
pub name: Option<String>,
pub quantity: Option<i32>,
pub cents: Option<i32>,
pub description: Option<String>,
pub featured: Option<bool>,
pub category_path: Option<String>,
pub photo_set: Option<i32>,
}
impl ProductPatch {
pub fn patch(self, product: &mut Product) {
if let Some(name) = self.name {
product.name = name;
}
if let Some(category) = self.category_path {
product.category = category;
}
if let Some(description) = self.description {
product.description = description;
}
product.quantity = self.quantity.unwrap_or(product.quantity);
product.cents = self.cents.unwrap_or(product.cents);
product.featured = self.featured.unwrap_or(product.featured);
}
}
|