From da10d0e0cebc1142852b959cea93c8b80801d565 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 9 Sep 2018 12:26:37 -0700 Subject: generic edit accept, and per-row variant The per-row variant is for use with cockroach. --- rust/src/api_helpers.rs | 50 ++++++++++++------------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) (limited to 'rust/src/api_helpers.rs') diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index 925a6073..8ab9dcb3 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -1,18 +1,20 @@ use data_encoding::BASE32_NOPAD; use database_models::*; use database_schema::*; +use fatcat_api::models::*; use diesel; use diesel::prelude::*; use errors::*; use regex::Regex; use std::str::FromStr; use uuid::Uuid; +use database_entity_crud::EntityCrud; pub type DbConn = diesel::r2d2::PooledConnection>; /// This function should always be run within a transaction -pub fn get_or_create_editgroup(editor_id: Uuid, conn: &PgConnection) -> Result { +pub fn get_or_create_editgroup(editor_id: Uuid, conn: &DbConn) -> Result { // check for current active let ed_row: EditorRow = editor::table.find(editor_id).first(conn)?; if let Some(current) = ed_row.active_editgroup_id { @@ -30,7 +32,7 @@ pub fn get_or_create_editgroup(editor_id: Uuid, conn: &PgConnection) -> Result Result { +pub fn accept_editgroup(editgroup_id: Uuid, conn: &DbConn) -> Result { // check that we haven't accepted already (in changelog) // NB: could leave this to a UNIQUE constraint let count: i64 = changelog::table @@ -41,41 +43,13 @@ pub fn accept_editgroup(editgroup_id: Uuid, conn: &PgConnection) -> Result(editgroup_id) - .execute(conn)?; - } + // copy edit columns to ident table + let eg_id = FatCatId::from_uuid(&editgroup_id); + ContainerEntity::db_accept_edits(conn, eg_id)?; + CreatorEntity::db_accept_edits(conn, eg_id)?; + FileEntity::db_accept_edits(conn, eg_id)?; + ReleaseEntity::db_accept_edits(conn, eg_id)?; + WorkEntity::db_accept_edits(conn, eg_id)?; // append log/changelog row let entry: ChangelogRow = diesel::insert_into(changelog::table) @@ -91,7 +65,7 @@ pub fn accept_editgroup(editgroup_id: Uuid, conn: &PgConnection) -> Result