summaryrefslogtreecommitdiff
path: root/dichroism/src/models
diff options
context:
space:
mode:
Diffstat (limited to 'dichroism/src/models')
-rw-r--r--dichroism/src/models/photo.rs15
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)))
}
}