blob: f23146914b106608a60dba79fe98b365133d5759 (
plain) (
tree)
|
|
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);
}
}
|