summaryrefslogtreecommitdiff
path: root/dichroism/src
diff options
context:
space:
mode:
Diffstat (limited to 'dichroism/src')
-rw-r--r--dichroism/src/config.rs2
-rw-r--r--dichroism/src/dtos/mod.rs6
-rw-r--r--dichroism/src/handlers.rs4
-rw-r--r--dichroism/src/main.rs3
-rw-r--r--dichroism/src/models/photo.rs15
-rw-r--r--dichroism/src/repo/entities/mod.rs (renamed from dichroism/src/entities/mod.rs)8
-rw-r--r--dichroism/src/repo/mod.rs (renamed from dichroism/src/product_repo.rs)3
7 files changed, 22 insertions, 19 deletions
diff --git a/dichroism/src/config.rs b/dichroism/src/config.rs
index 0dbc10e..2031ecc 100644
--- a/dichroism/src/config.rs
+++ b/dichroism/src/config.rs
@@ -10,7 +10,7 @@ use toml::from_str;
pub static CONFIG_INSTANCE: Lazy<Config> = Lazy::new(|| {
Config::from_toml().unwrap_or_else(|e| {
- eprintln!("Error: {}", e.to_string());
+ eprintln!("Error parsing config: {}", e.to_string());
std::process::exit(1);
})
});
diff --git a/dichroism/src/dtos/mod.rs b/dichroism/src/dtos/mod.rs
index 76b04c7..d7e1ab5 100644
--- a/dichroism/src/dtos/mod.rs
+++ b/dichroism/src/dtos/mod.rs
@@ -62,9 +62,9 @@ impl From<models::Product> for Product {
quantity: p.quantity,
featured: p.featured,
category: p.category,
- photo_fullsize: p.photo_set.fullsize.path,
- photo_base: p.photo_set.base.path,
- photo_thumbnail: p.photo_set.thumbnail.path,
+ photo_fullsize: p.photo_set.fullsize.filename,
+ photo_base: p.photo_set.base.filename,
+ photo_thumbnail: p.photo_set.thumbnail.filename,
}
}
}
diff --git a/dichroism/src/handlers.rs b/dichroism/src/handlers.rs
index 23d2039..b4b117c 100644
--- a/dichroism/src/handlers.rs
+++ b/dichroism/src/handlers.rs
@@ -1,5 +1,5 @@
use crate::dtos::*;
-use crate::product_repo;
+use crate::repo;
use crate::types::DbPool;
use actix_web::{get, patch, post, web, Error, HttpResponse, Responder};
@@ -11,7 +11,7 @@ async fn hello() -> impl Responder {
#[get("/products")]
async fn get_products(pool: web::Data<DbPool>) -> Result<HttpResponse, Error> {
let conn = pool.get().expect("Couldn't get DB connection from pool.");
- let products: Vec<Product> = web::block(move || product_repo::read_products(&conn))
+ let products: Vec<Product> = web::block(move || repo::read_products(&conn))
.await
.map_err(|e| {
eprintln!("{}", e);
diff --git a/dichroism/src/main.rs b/dichroism/src/main.rs
index 5ecd9a4..c255717 100644
--- a/dichroism/src/main.rs
+++ b/dichroism/src/main.rs
@@ -14,11 +14,10 @@ use result::Result;
mod config;
mod constants;
mod dtos;
-mod entities;
mod error;
mod handlers;
mod models;
-mod product_repo;
+mod repo;
mod result;
mod schema;
mod types;
diff --git a/dichroism/src/models/photo.rs b/dichroism/src/models/photo.rs
index 6069085..8c1435e 100644
--- a/dichroism/src/models/photo.rs
+++ b/dichroism/src/models/photo.rs
@@ -7,12 +7,12 @@ use uuid::Uuid;
#[derive(Debug, Queryable, Serialize, Clone)]
pub struct Photo {
- pub path: String,
+ pub filename: String,
}
impl Photo {
- pub fn from_path(path: String) -> Self {
- Self { path }
+ pub fn from_filename(filename: String) -> Self {
+ Self { filename }
}
pub fn from_image(image: &DynamicImage) -> Result<Self> {
@@ -24,8 +24,11 @@ impl Photo {
path.set_extension("jpg");
image.save(&path)?;
- Ok(Self {
- path: path.to_str().ok_or(DichroismError::ImageWrite)?.to_string(),
- })
+ let filename = path
+ .file_name()
+ .ok_or(DichroismError::ImageWrite)?
+ .to_str()
+ .ok_or(DichroismError::ImageWrite)?;
+ Ok(Self::from_filename(String::from(filename)))
}
}
diff --git a/dichroism/src/entities/mod.rs b/dichroism/src/repo/entities/mod.rs
index a127ef1..2cff899 100644
--- a/dichroism/src/entities/mod.rs
+++ b/dichroism/src/repo/entities/mod.rs
@@ -26,10 +26,10 @@ impl Into<models::Product> for Product {
featured: self.featured != 0, // TODO: is this safe?
category: String::new(), // TODO: real category
photo_set: models::PhotoSet::from_photos(
- models::Photo::from_path(self.original),
- models::Photo::from_path(self.fullsize),
- models::Photo::from_path(self.base),
- models::Photo::from_path(self.thumbnail),
+ models::Photo::from_filename(self.original),
+ models::Photo::from_filename(self.fullsize),
+ models::Photo::from_filename(self.base),
+ models::Photo::from_filename(self.thumbnail),
),
}
}
diff --git a/dichroism/src/product_repo.rs b/dichroism/src/repo/mod.rs
index 6f40b20..0df8aad 100644
--- a/dichroism/src/product_repo.rs
+++ b/dichroism/src/repo/mod.rs
@@ -1,9 +1,10 @@
-use crate::entities;
use crate::models;
use crate::schema::*;
use diesel::prelude::*;
use diesel::result::Error;
+mod entities;
+
type DBConn = SqliteConnection;
pub fn read_products(conn: &DBConn) -> Result<Vec<models::Product>, Error> {