aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/api_entity_crud.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/api_entity_crud.rs')
-rw-r--r--rust/src/api_entity_crud.rs37
1 files changed, 32 insertions, 5 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 6bbfcdc4..401b9835 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -1,4 +1,5 @@
use api_helpers::*;
+use api_server::get_release_files;
use chrono;
use database_models::*;
use database_schema::*;
@@ -45,6 +46,7 @@ where
// Generic Methods
fn db_get(conn: &DbConn, ident: FatCatId) -> Result<Self>;
fn db_get_rev(conn: &DbConn, rev_id: Uuid) -> Result<Self>;
+ fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()>;
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow>;
fn db_create_batch(
conn: &DbConn,
@@ -114,6 +116,14 @@ macro_rules! generic_db_get_rev {
};
}
+macro_rules! generic_db_expand {
+ () => {
+ fn db_expand(&mut self, _conn: &DbConn, _expand: ExpandFlags) -> Result<()> {
+ Ok(())
+ }
+ };
+}
+
macro_rules! generic_db_create {
// TODO: this path should call generic_db_create_batch
($ident_table: ident, $edit_table: ident) => {
@@ -387,13 +397,13 @@ impl EntityCrud for ContainerEntity {
generic_parse_editgroup_id!();
generic_db_get!(container_ident, container_rev);
generic_db_get_rev!(container_rev);
+ generic_db_expand!();
generic_db_create!(container_ident, container_edit);
generic_db_create_batch!(container_ident, container_edit);
generic_db_update!(container_ident, container_edit);
generic_db_delete!(container_ident, container_edit);
generic_db_get_history!(container_edit);
generic_db_accept_edits_batch!("container");
- //generic_db_accept_edits_each!(container_ident, container_edit);
generic_db_insert_rev!();
fn db_from_row(
@@ -468,13 +478,13 @@ impl EntityCrud for CreatorEntity {
generic_parse_editgroup_id!();
generic_db_get!(creator_ident, creator_rev);
generic_db_get_rev!(creator_rev);
+ generic_db_expand!();
generic_db_create!(creator_ident, creator_edit);
generic_db_create_batch!(creator_ident, creator_edit);
generic_db_update!(creator_ident, creator_edit);
generic_db_delete!(creator_ident, creator_edit);
generic_db_get_history!(creator_edit);
generic_db_accept_edits_batch!("creator");
- //generic_db_accept_edits_each!(creator_ident, creator_edit);
generic_db_insert_rev!();
fn db_from_row(
@@ -546,13 +556,13 @@ impl EntityCrud for FileEntity {
generic_parse_editgroup_id!();
generic_db_get!(file_ident, file_rev);
generic_db_get_rev!(file_rev);
+ generic_db_expand!();
generic_db_create!(file_ident, file_edit);
generic_db_create_batch!(file_ident, file_edit);
generic_db_update!(file_ident, file_edit);
generic_db_delete!(file_ident, file_edit);
generic_db_get_history!(file_edit);
generic_db_accept_edits_batch!("file");
- //generic_db_accept_edits_each!(file_ident, file_edit);
generic_db_insert_rev!();
fn db_from_row(
@@ -690,9 +700,26 @@ impl EntityCrud for ReleaseEntity {
generic_db_delete!(release_ident, release_edit);
generic_db_get_history!(release_edit);
generic_db_accept_edits_batch!("release");
- //generic_db_accept_edits_each!(release_ident, release_edit);
generic_db_insert_rev!();
+ fn db_expand(&mut self, conn: &DbConn, expand: ExpandFlags) -> Result<()> {
+
+ let ident = match &self.ident {
+ None => bail!("Can't expand a non-concrete entity"),
+ Some(s) => FatCatId::from_str(&s)?
+ };
+ if expand.files {
+ self.files = Some(get_release_files(ident, conn)?);
+ }
+ if expand.container {
+ if let Some(ref cid) = self.container_id {
+ self.container =
+ Some(ContainerEntity::db_get(conn, FatCatId::from_str(&cid)?)?);
+ }
+ }
+ Ok(())
+ }
+
fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result<Self::EditRow> {
let mut edits = Self::db_create_batch(conn, edit_context, &[self])?;
// probably a more elegant way to destroy the vec and take first element
@@ -1062,13 +1089,13 @@ impl EntityCrud for WorkEntity {
generic_parse_editgroup_id!();
generic_db_get!(work_ident, work_rev);
generic_db_get_rev!(work_rev);
+ generic_db_expand!();
generic_db_create!(work_ident, work_edit);
generic_db_create_batch!(work_ident, work_edit);
generic_db_update!(work_ident, work_edit);
generic_db_delete!(work_ident, work_edit);
generic_db_get_history!(work_edit);
generic_db_accept_edits_batch!("work");
- //generic_db_accept_edits_each!(work_ident, work_edit);
generic_db_insert_rev!();
fn db_from_row(