diff options
Diffstat (limited to 'dichroism/src/repo')
-rw-r--r-- | dichroism/src/repo/entities/product.rs | 3 | ||||
-rw-r--r-- | dichroism/src/repo/product_repo.rs | 32 |
2 files changed, 21 insertions, 14 deletions
diff --git a/dichroism/src/repo/entities/product.rs b/dichroism/src/repo/entities/product.rs index e6ba223..81f3d9e 100644 --- a/dichroism/src/repo/entities/product.rs +++ b/dichroism/src/repo/entities/product.rs @@ -14,6 +14,7 @@ pub struct Product { pub fullsize: String, pub base: String, pub thumbnail: String, + pub category: String, } impl Into<models::Product> for Product { @@ -25,7 +26,7 @@ impl Into<models::Product> for Product { quantity: self.quantity, cents: self.cents, featured: self.featured != 0, // TODO: is this safe? - category: String::new(), // TODO: real category + category: self.category, photo_set: models::PhotoSet { id: Some(self.photo_set_id), original: models::Photo::new(self.original), diff --git a/dichroism/src/repo/product_repo.rs b/dichroism/src/repo/product_repo.rs index 7b3aaac..d7dff65 100644 --- a/dichroism/src/repo/product_repo.rs +++ b/dichroism/src/repo/product_repo.rs @@ -21,19 +21,23 @@ pub fn store(conn: &DBConn, mut product: models::Product) -> Result<models::Prod pub fn find_all(conn: &DBConn) -> Result<Vec<models::Product>, Error> { use crate::schema::*; - let query = products::table.inner_join(photo_sets::table).select(( - products::id, - products::name, - products::description, - products::quantity, - products::cents, - products::featured, - photo_sets::id, - photo_sets::original, - photo_sets::fullsize, - photo_sets::base, - photo_sets::thumbnail, - )); + let query = products::table + .inner_join(photo_sets::table) + .inner_join(categories::table) + .select(( + products::id, + products::name, + products::description, + products::quantity, + products::cents, + products::featured, + photo_sets::id, + photo_sets::original, + photo_sets::fullsize, + photo_sets::base, + photo_sets::thumbnail, + categories::path, + )); Ok(query .load::<Product>(conn)? .into_iter() @@ -45,6 +49,7 @@ pub fn find(conn: &DBConn, dbid: i32) -> Result<Option<models::Product>, Error> use crate::schema::*; let query = products::table .inner_join(photo_sets::table) + .inner_join(categories::table) .filter(products::id.eq(dbid)) .select(( products::id, @@ -58,6 +63,7 @@ pub fn find(conn: &DBConn, dbid: i32) -> Result<Option<models::Product>, Error> photo_sets::fullsize, photo_sets::base, photo_sets::thumbnail, + categories::path, )); let product = query.first::<Product>(conn).map(|p| p.into()); match product { |