summaryrefslogtreecommitdiffstats
path: root/rust/src/editing_crud.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/editing_crud.rs')
-rw-r--r--rust/src/editing_crud.rs17
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);