diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-21 14:10:56 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-21 14:10:56 -0800 |
commit | 1a15624e13bfe0a3bdddb1f0c5bf8940c9f04a04 (patch) | |
tree | 02029146a5bc5079ec2c85dc7dc88c47a69a5352 /rust/src/api_helpers.rs | |
parent | 42265350c9f0b7a5731103c191a807a691f8f2ef (diff) | |
download | fatcat-1a15624e13bfe0a3bdddb1f0c5bf8940c9f04a04.tar.gz fatcat-1a15624e13bfe0a3bdddb1f0c5bf8940c9f04a04.zip |
more edit edgecases; editgroup status check
Diffstat (limited to 'rust/src/api_helpers.rs')
-rw-r--r-- | rust/src/api_helpers.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index 77377531..b6525546 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -21,6 +21,22 @@ pub struct EditContext { pub autoaccept: bool, } +impl EditContext { + + /// This function should always be run within a transaction + pub fn check(&self, conn: &DbConn) -> Result<()> { + let count: i64 = changelog::table + .filter(changelog::editgroup_id.eq(&self.editgroup_id.to_uuid())) + .count() + .get_result(conn)?; + if count > 0 { + return Err(ErrorKind::EditgroupAlreadyAccepted(self.editgroup_id.to_string()).into()); + } + return Ok(()); + } +} + + #[derive(Clone, Copy, PartialEq)] pub struct ExpandFlags { pub files: bool, @@ -202,6 +218,7 @@ pub fn get_or_create_editgroup(editor_id: Uuid, conn: &DbConn) -> Result<Uuid> { pub fn accept_editgroup(editgroup_id: FatCatId, conn: &DbConn) -> Result<ChangelogRow> { // check that we haven't accepted already (in changelog) // NB: could leave this to a UNIQUE constraint + // TODO: redundant with check_edit_context let count: i64 = changelog::table .filter(changelog::editgroup_id.eq(editgroup_id.to_uuid())) .count() |