From dcc96d0b349583e5d6a0f25ae1f7a3ffa3769788 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Mon, 2 Nov 2020 20:36:18 -0500 Subject: swapped json payload url encoded images for multipart form data --- dichroism/src/dtos/mod.rs | 2 ++ dichroism/src/dtos/photo_set_get.rs | 22 ++++++++++++++++++++++ dichroism/src/dtos/product_patch.rs | 22 +++++++++++++++++++++- dichroism/src/dtos/product_post.rs | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 dichroism/src/dtos/photo_set_get.rs (limited to 'dichroism/src/dtos') diff --git a/dichroism/src/dtos/mod.rs b/dichroism/src/dtos/mod.rs index cc8edd1..a3e27e5 100644 --- a/dichroism/src/dtos/mod.rs +++ b/dichroism/src/dtos/mod.rs @@ -1,7 +1,9 @@ +mod photo_set_get; mod product_get; mod product_patch; mod product_post; +pub use photo_set_get::*; pub use product_get::*; pub use product_patch::*; pub use product_post::*; diff --git a/dichroism/src/dtos/photo_set_get.rs b/dichroism/src/dtos/photo_set_get.rs new file mode 100644 index 0000000..0736617 --- /dev/null +++ b/dichroism/src/dtos/photo_set_get.rs @@ -0,0 +1,22 @@ +use crate::models::PhotoSet; + +#[derive(Debug, Serialize)] +pub struct PhotoSetGet { + pub id: i32, + pub original: String, + pub fullsize: String, + pub base: String, + pub thumbnail: String, +} + +impl From for PhotoSetGet { + fn from(p: PhotoSet) -> Self { + Self { + id: p.id.unwrap_or(-1), + original: p.original.id, + fullsize: p.fullsize.id, + base: p.base.id, + thumbnail: p.thumbnail.id, + } + } +} diff --git a/dichroism/src/dtos/product_patch.rs b/dichroism/src/dtos/product_patch.rs index ed8bf1a..f231469 100644 --- a/dichroism/src/dtos/product_patch.rs +++ b/dichroism/src/dtos/product_patch.rs @@ -1,3 +1,5 @@ +use crate::models::Product; + #[derive(Debug, Deserialize)] pub struct ProductPatch { pub id: i32, @@ -7,5 +9,23 @@ pub struct ProductPatch { pub description: Option, pub featured: Option, pub category_path: Option, - pub photo_data: Option, + pub photo_set: Option, +} + +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); + } } diff --git a/dichroism/src/dtos/product_post.rs b/dichroism/src/dtos/product_post.rs index ef07536..ee3ba03 100644 --- a/dichroism/src/dtos/product_post.rs +++ b/dichroism/src/dtos/product_post.rs @@ -6,5 +6,5 @@ pub struct ProductPost { pub description: String, pub featured: bool, pub category_path: String, - pub photo_data: String, + pub photo_set: i32, } -- cgit v1.2.3