diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-23 08:10:13 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-23 08:10:13 -0400 |
commit | 00c71f6baff136a88805ca2e3f9ef72453ac9f35 (patch) | |
tree | 49db87097f949edce1f6639ba4118cff852e3937 /dichroism/src/models | |
parent | 5cb0869b94fc8b9aff564055af9a60046de7b028 (diff) | |
download | theglassyladies-00c71f6baff136a88805ca2e3f9ef72453ac9f35.tar.xz theglassyladies-00c71f6baff136a88805ca2e3f9ef72453ac9f35.zip |
moved entities under repo; photos now hold onto just the filename
Diffstat (limited to 'dichroism/src/models')
-rw-r--r-- | dichroism/src/models/photo.rs | 15 |
1 files changed, 9 insertions, 6 deletions
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))) } } |