summaryrefslogtreecommitdiff
path: root/dichroism/src/dtos
diff options
context:
space:
mode:
Diffstat (limited to 'dichroism/src/dtos')
-rw-r--r--dichroism/src/dtos/mod.rs2
-rw-r--r--dichroism/src/dtos/photo_set_get.rs22
-rw-r--r--dichroism/src/dtos/product_patch.rs22
-rw-r--r--dichroism/src/dtos/product_post.rs2
4 files changed, 46 insertions, 2 deletions
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<PhotoSet> 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<String>,
pub featured: Option<bool>,
pub category_path: Option<String>,
- pub photo_data: 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);
+ }
}
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,
}