From 11fdff350e0549d46a8a7b5e74451e08ce067cb2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 12 Oct 2021 19:56:08 -0700 Subject: rust: implement scheman and API changes --- rust/src/editing_crud.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'rust/src/editing_crud.rs') diff --git a/rust/src/editing_crud.rs b/rust/src/editing_crud.rs index 8da3cabd..fa39fdfb 100644 --- a/rust/src/editing_crud.rs +++ b/rust/src/editing_crud.rs @@ -28,6 +28,7 @@ use uuid::Uuid; pub trait EditorCrud { fn db_get(conn: &DbConn, editor_id: FatcatId) -> Result; + fn db_get_username(conn: &DbConn, username: &str) -> Result; fn db_create(&self, conn: &DbConn) -> Result; fn db_update_username(&self, conn: &DbConn, editor_id: FatcatId) -> Result; } @@ -45,6 +46,22 @@ impl EditorCrud for Editor { Ok(editor) } + fn db_get_username(conn: &DbConn, username: &str) -> Result { + let editor: EditorRow = match editor::table + .filter(editor::username.eq(username)) + .get_result(conn) + { + Ok(ed) => ed, + Err(diesel::result::Error::NotFound) => { + return Err( + FatcatError::NotFound("editor".to_string(), username.to_string()).into(), + ); + } + other => other?, + }; + Ok(editor) + } + fn db_create(&self, conn: &DbConn) -> Result { identifiers::check_username(&self.username)?; let is_admin = self.is_admin.unwrap_or(false); -- cgit v1.2.3