diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-12 19:56:08 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2021-10-13 16:21:30 -0700 |
commit | 11fdff350e0549d46a8a7b5e74451e08ce067cb2 (patch) | |
tree | 20f48fb619e4267bb066340e249acc14649ae3da /rust/src/editing_crud.rs | |
parent | 8d1f8d02f2e43c13d35b57ff3a625ab5de6c51c7 (diff) | |
download | fatcat-11fdff350e0549d46a8a7b5e74451e08ce067cb2.tar.gz fatcat-11fdff350e0549d46a8a7b5e74451e08ce067cb2.zip |
rust: implement scheman and API changes
Diffstat (limited to 'rust/src/editing_crud.rs')
-rw-r--r-- | rust/src/editing_crud.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<EditorRow>; + fn db_get_username(conn: &DbConn, username: &str) -> Result<EditorRow>; fn db_create(&self, conn: &DbConn) -> Result<EditorRow>; fn db_update_username(&self, conn: &DbConn, editor_id: FatcatId) -> Result<EditorRow>; } @@ -45,6 +46,22 @@ impl EditorCrud for Editor { Ok(editor) } + fn db_get_username(conn: &DbConn, username: &str) -> Result<EditorRow> { + 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<EditorRow> { identifiers::check_username(&self.username)?; let is_admin = self.is_admin.unwrap_or(false); |