summaryrefslogtreecommitdiff
path: root/dichroism/src
diff options
context:
space:
mode:
Diffstat (limited to 'dichroism/src')
-rw-r--r--dichroism/src/repo/entities/product.rs3
-rw-r--r--dichroism/src/repo/product_repo.rs32
-rw-r--r--dichroism/src/schema.rs10
3 files changed, 31 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 {
diff --git a/dichroism/src/schema.rs b/dichroism/src/schema.rs
index fb59bf6..45501cf 100644
--- a/dichroism/src/schema.rs
+++ b/dichroism/src/schema.rs
@@ -1,4 +1,11 @@
table! {
+ categories (id) {
+ id -> Integer,
+ path -> Text,
+ }
+}
+
+table! {
photo_sets (id) {
id -> Integer,
base -> Text,
@@ -17,12 +24,15 @@ table! {
name -> Text,
description -> Text,
featured -> Integer,
+ category -> Integer,
}
}
+joinable!(products -> categories (category));
joinable!(products -> photo_sets (photo_set));
allow_tables_to_appear_in_same_query!(
+ categories,
photo_sets,
products,
);