summaryrefslogtreecommitdiffstats
path: root/rust/src/editing_crud.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-11 14:52:44 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-11 14:52:44 -0800
commit54e34ddd56b705cba239f88a9239c603d3ecd20e (patch)
tree5007cbc2d315d04b5788eb6cec0b7537e8baa51b /rust/src/editing_crud.rs
parentcd5cf1b9f7a50cd3c2f2a42b4a0b3743a5c31d7e (diff)
downloadfatcat-54e34ddd56b705cba239f88a9239c603d3ecd20e.tar.gz
fatcat-54e34ddd56b705cba239f88a9239c603d3ecd20e.zip
yet more edit lifecycle progress
Diffstat (limited to 'rust/src/editing_crud.rs')
-rw-r--r--rust/src/editing_crud.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/rust/src/editing_crud.rs b/rust/src/editing_crud.rs
index 86cc2fb3..d3782f7b 100644
--- a/rust/src/editing_crud.rs
+++ b/rust/src/editing_crud.rs
@@ -19,12 +19,11 @@ use uuid::Uuid;
* Generic verbs/actions look like:
*
* - db_get (single)
- * - db_get_range (group; by timestamp)
+ * - db_get_range (group; by timestamp, with limits)
* - db_create (single)
* - db_update (single)
* - db_expand (single)
*
- * Annotations can be fetch with a join on either editgroup or editor, with same range parameters.
*/
pub trait EditorCrud {
@@ -42,14 +41,14 @@ impl EditorCrud for Editor {
identifiers::check_username(&self.username)?;
let is_admin = self.is_admin.unwrap_or(false);
let is_bot = self.is_bot.unwrap_or(false);
- let ed: EditorRow = diesel::insert_into(editor::table)
+ let row: EditorRow = diesel::insert_into(editor::table)
.values((
editor::username.eq(&self.username),
editor::is_admin.eq(is_admin),
editor::is_bot.eq(is_bot),
))
.get_result(conn)?;
- Ok(ed)
+ Ok(row)
}
fn db_update_username(&self, conn: &DbConn, editor_id: FatcatId) -> Result<EditorRow> {
@@ -88,8 +87,8 @@ pub trait EditgroupCrud {
}
impl EditgroupCrud for Editgroup {
- // XXX: this should probably *alwas* retun changelog status as well. If we do that, can we get rid
- // of the is_accepted thing? no, still want it as denormalized speed-up in some queries/filters.
+ // XXX: this could *alwas* return changelog status as well. If we do that, can we get rid of
+ // the is_accepted thing? no, still want it as denormalized speed-up in some queries/filters.
/// This method does *not* expand the 'edits'; currently that's still done in the endpoint
/// handler, but it probably should be done in this trait with a db_expand()
@@ -111,8 +110,16 @@ impl EditgroupCrud for Editgroup {
Ok(row)
}
+ /// Note: this *still* doesn't epand the 'edits', at least yet.
fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()> {
- // XXX: impl
+ if expand.editors {
+ let editor_id = FatcatId::from_str(
+ self.editor_id
+ .as_ref()
+ .expect("tried to expand bare Editor model"),
+ )?;
+ self.editor = Some(Editor::db_get(conn, editor_id)?.into_model());
+ }
Ok(())
}
@@ -244,7 +251,15 @@ impl EditgroupAnnotationCrud for EditgroupAnnotation {
}
fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()> {
- unimplemented!()
+ if expand.editors {
+ let editor_id = FatcatId::from_str(
+ self.editor_id
+ .as_ref()
+ .expect("tried to expand bare Editor model"),
+ )?;
+ self.editor = Some(Editor::db_get(conn, editor_id)?.into_model());
+ }
+ Ok(())
}
fn db_get_range_for_editor(