diff options
author | Adam T. Carpenter <atc@53hor.net> | 2022-10-26 21:02:31 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2022-10-26 21:02:31 -0400 |
commit | 9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f (patch) | |
tree | db9ca419266117facecdff6d30460669f3148efb /dichroism/src/repo/photo_set_repo.rs | |
parent | f243a3b7341012227d6e8342a65f9c5d7784256f (diff) | |
download | theglassyladies-9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f.tar.xz theglassyladies-9f3098e80c6b6c87e9bfbfe36239a39e5cafb29f.zip |
init: add some stories and personas and begin layout out domain
Diffstat (limited to 'dichroism/src/repo/photo_set_repo.rs')
-rw-r--r-- | dichroism/src/repo/photo_set_repo.rs | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/dichroism/src/repo/photo_set_repo.rs b/dichroism/src/repo/photo_set_repo.rs deleted file mode 100644 index 56ca962..0000000 --- a/dichroism/src/repo/photo_set_repo.rs +++ /dev/null @@ -1,44 +0,0 @@ -use super::entities::*; -use super::DBConn; -use crate::models; -use diesel::{insert_into, prelude::*, result::Error, update}; - -pub fn store(conn: &DBConn, mut photo_set: models::PhotoSet) -> Result<models::PhotoSet, Error> { - use crate::schema::photo_sets::dsl::*; - if let Some(photo_set_id) = photo_set.id { - // update - let form = PhotoSetForm::from(photo_set.clone()); - update(photo_sets.filter(id.eq(photo_set_id))) - .set(&form) - .execute(conn)?; - } else { - // insert - photo_set.id = Some(find_next_id(conn)); - let form = PhotoSetForm::from(photo_set.clone()); - insert_into(photo_sets).values(&form).execute(conn)?; - } - Ok(photo_set) -} - -pub fn find(conn: &DBConn, dbid: i32) -> Result<Option<models::PhotoSet>, Error> { - use crate::schema::photo_sets::dsl::*; - let query = photo_sets - .filter(id.eq(dbid)) - .select((id, original, fullsize, base, thumbnail)); - let photo_set = query.first::<PhotoSet>(conn).map(|p| p.into()); - match photo_set { - Ok(p) => Ok(Some(p)), - Err(Error::NotFound) => Ok(None), - Err(e) => Err(e), - } -} - -fn find_next_id(conn: &DBConn) -> i32 { - use crate::schema::photo_sets::dsl::*; - let last_id = photo_sets - .select(id) - .order(id.desc()) - .first::<i32>(conn) - .unwrap_or(0); - last_id + 1 -} |