aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-05-14 18:29:51 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-05-14 18:29:51 -0700
commita69fb6bfd45b99a2001a12524714fc2542a6d9ca (patch)
treeb6b100d2fc235b439c98ad9f1ee4915b5ac83660 /rust
parent7c18e1d22b16bb920c9bb9a788691820bbdb2bfa (diff)
downloadfatcat-a69fb6bfd45b99a2001a12524714fc2542a6d9ca.tar.gz
fatcat-a69fb6bfd45b99a2001a12524714fc2542a6d9ca.zip
rust: return editors and cl index for editgroup more often
Diffstat (limited to 'rust')
-rw-r--r--rust/src/database_models.rs4
-rw-r--r--rust/src/editing_crud.rs2
-rw-r--r--rust/src/endpoint_handlers.rs14
-rw-r--r--rust/src/endpoints.rs7
-rw-r--r--rust/src/entity_crud.rs8
5 files changed, 20 insertions, 15 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index 1b0c2de3..34ce1de6 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -662,11 +662,11 @@ pub struct EditgroupRow {
impl EditgroupRow {
/// Returns an Editgroup API model *without* the entity edits actually populated. Useful for,
/// eg, entity history queries (where we already have the entity edit we want)
- pub fn into_model_partial(self, changelog_index: Option<i64>) -> Editgroup {
+ pub fn into_model_partial(self, changelog_index: Option<i64>, editor: Option<Editor>) -> Editgroup {
Editgroup {
editgroup_id: Some(uuid2fcid(&self.id)),
editor_id: Some(uuid2fcid(&self.editor_id)),
- editor: None,
+ editor: editor,
changelog_index: changelog_index,
submitted: self
.submitted
diff --git a/rust/src/editing_crud.rs b/rust/src/editing_crud.rs
index 405afcc0..2526ef2b 100644
--- a/rust/src/editing_crud.rs
+++ b/rust/src/editing_crud.rs
@@ -144,7 +144,7 @@ impl EditgroupCrud for Editgroup {
let editor_id = FatcatId::from_str(
self.editor_id
.as_ref()
- .expect("tried to expand bare Editor model"),
+ .expect("tried to expand bare Editgroup model"),
)?;
self.editor = Some(Editor::db_get(conn, editor_id)?.into_model());
}
diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs
index dcc647ea..ba8505e1 100644
--- a/rust/src/endpoint_handlers.rs
+++ b/rust/src/endpoint_handlers.rs
@@ -460,7 +460,7 @@ impl Server {
editgroup: models::Editgroup,
) -> Result<Editgroup> {
let row = editgroup.db_create(conn, false)?;
- Ok(row.into_model_partial(None))
+ Ok(row.into_model_partial(None, None))
}
pub fn get_editgroup_handler(
@@ -469,7 +469,8 @@ impl Server {
editgroup_id: FatcatId,
) -> Result<Editgroup> {
let (eg_row, cl_row) = Editgroup::db_get_with_changelog(conn, editgroup_id)?;
- let mut editgroup = eg_row.into_model_partial(cl_row.map(|cl| cl.id));
+ let editor = Editor::db_get(&conn, FatcatId::from_uuid(&eg_row.editor_id))?.into_model();
+ let mut editgroup = eg_row.into_model_partial(cl_row.map(|cl| cl.id), Some(editor));
let edits = EditgroupEdits {
containers: Some(
@@ -546,17 +547,18 @@ impl Server {
) -> Result<Vec<ChangelogEntry>> {
let limit = limit.unwrap_or(50);
- let changes: Vec<(ChangelogRow, EditgroupRow)> = changelog::table
- .inner_join(editgroup::table)
+ let changes: Vec<(EditgroupRow, ChangelogRow, EditorRow)> = editgroup::table
+ .inner_join(changelog::table)
+ .inner_join(editor::table)
.order(changelog::id.desc())
.limit(limit)
.load(conn)?;
let entries = changes
.into_iter()
- .map(|(cl_row, eg_row)| ChangelogEntry {
+ .map(|(eg_row, cl_row, editor_row)| ChangelogEntry {
index: cl_row.id,
- editgroup: Some(eg_row.into_model_partial(None)),
+ editgroup: Some(eg_row.into_model_partial(Some(cl_row.id), Some(editor_row.into_model()))),
editgroup_id: uuid2fcid(&cl_row.editgroup_id),
timestamp: chrono::DateTime::from_utc(cl_row.timestamp, chrono::Utc),
})
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs
index 7d6db908..96a4700b 100644
--- a/rust/src/endpoints.rs
+++ b/rust/src/endpoints.rs
@@ -788,9 +788,10 @@ impl Api for Server {
let limit = cmp::min(100, limit.unwrap_or(20)) as u64;
let rows =
Editgroup::db_get_range_for_editor(&conn, editor_id, limit, since, before)?;
+ let editor = Editor::db_get(&conn, editor_id)?.into_model();
Ok(rows
.into_iter()
- .map(|(eg, cl)| eg.into_model_partial(cl.map(|v| v.id)))
+ .map(|(eg, cl)| eg.into_model_partial(cl.map(|v| v.id), Some(editor.clone())))
.collect())
})
.map_err(|e: Error| FatcatError::from(e))
@@ -931,7 +932,7 @@ impl Api for Server {
let row = Editgroup::db_get_range_reviewable(&conn, limit, since, before)?;
let mut editgroups: Vec<Editgroup> = row
.into_iter()
- .map(|eg| eg.into_model_partial(None))
+ .map(|eg| eg.into_model_partial(None, None))
.collect();
if let Some(expand) = expand {
let expand = ExpandFlags::from_str(&expand)?;
@@ -1032,7 +1033,7 @@ impl Api for Server {
};
editgroup
.db_update(&conn, editgroup_id, submit)
- .map(|eg| eg.into_model_partial(None)) // can't update an accepted editgroup
+ .map(|eg| eg.into_model_partial(None, None)) // can't update an accepted editgroup
})
.map_err(|e: Error| FatcatError::from(e))
{
diff --git a/rust/src/entity_crud.rs b/rust/src/entity_crud.rs
index bdb83560..269bfdf6 100644
--- a/rust/src/entity_crud.rs
+++ b/rust/src/entity_crud.rs
@@ -538,9 +538,10 @@ macro_rules! generic_db_get_history {
) -> Result<Vec<EntityHistoryEntry>> {
let limit = limit.unwrap_or(50); // TODO: make a static
- let rows: Vec<(EditgroupRow, ChangelogRow, Self::EditRow)> = editgroup::table
+ let rows: Vec<(EditgroupRow, ChangelogRow, Self::EditRow, EditorRow)> = editgroup::table
.inner_join(changelog::table)
.inner_join($edit_table::table)
+ .inner_join(editor::table)
.filter($edit_table::ident_id.eq(ident.to_uuid()))
.order(changelog::id.desc())
.limit(limit)
@@ -548,10 +549,11 @@ macro_rules! generic_db_get_history {
let history: Result<Vec<EntityHistoryEntry>> = rows
.into_iter()
- .map(|(eg_row, cl_row, e_row)| {
+ .map(|(eg_row, cl_row, e_row, editor_row)| {
+ let editor = editor_row.into_model();
Ok(EntityHistoryEntry {
edit: e_row.into_model()?,
- editgroup: eg_row.into_model_partial(None),
+ editgroup: eg_row.into_model_partial(Some(cl_row.id), Some(editor)),
changelog_entry: cl_row.into_model(),
})
})