From 00c71f6baff136a88805ca2e3f9ef72453ac9f35 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Fri, 23 Oct 2020 08:10:13 -0400 Subject: moved entities under repo; photos now hold onto just the filename --- dichroism/src/models/photo.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'dichroism/src/models') 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 { @@ -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))) } } -- cgit v1.2.3