summaryrefslogtreecommitdiff
path: root/dichroism/src/repo/product_repo.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-11-07 08:15:37 -0500
committerAdam T. Carpenter <atc@53hor.net>2020-11-07 08:15:37 -0500
commit2c408648c70614a88c0412faf6d3a00d147379a2 (patch)
tree6f8c84d0485917cf16b7f0420a2b74961177cc26 /dichroism/src/repo/product_repo.rs
parent01de71698b91bc61e61d076f9c25d1cabb039b18 (diff)
downloadtheglassyladies-2c408648c70614a88c0412faf6d3a00d147379a2.tar.xz
theglassyladies-2c408648c70614a88c0412faf6d3a00d147379a2.zip
Added category to products.
Diffstat (limited to 'dichroism/src/repo/product_repo.rs')
-rw-r--r--dichroism/src/repo/product_repo.rs32
1 files changed, 19 insertions, 13 deletions
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 {