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.rs108
1 files changed, 39 insertions, 69 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 461e1c7f..258355f8 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -147,10 +147,8 @@ macro_rules! generic_db_create_batch {
rev_id: Some(rev_id.clone()),
is_live: edit_context.autoaccept,
redirect_id: None,
- })
- .collect::<Vec<Self::IdentNewRow>>(),
- )
- .returning($ident_table::id)
+ }).collect::<Vec<Self::IdentNewRow>>(),
+ ).returning($ident_table::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = insert_into($edit_table::table)
.values(
@@ -164,10 +162,8 @@ macro_rules! generic_db_create_batch {
redirect_id: None,
prev_rev: None,
extra_json: edit_context.extra_json.clone(),
- })
- .collect::<Vec<Self::EditNewRow>>(),
- )
- .get_results(conn)?;
+ }).collect::<Vec<Self::EditNewRow>>(),
+ ).get_results(conn)?;
Ok(edits)
}
};
@@ -226,8 +222,7 @@ macro_rules! generic_db_delete {
$edit_table::redirect_id.eq(None::<Uuid>),
$edit_table::prev_rev.eq(current.rev_id),
$edit_table::extra_json.eq(&edit_context.extra_json),
- ))
- .get_result(conn)?;
+ )).get_result(conn)?;
Ok(edit)
}
@@ -259,8 +254,7 @@ macro_rules! generic_db_get_history {
editgroup: eg_row.into_model_partial(),
changelog_entry: cl_row.into_model(),
})
- })
- .collect();
+ }).collect();
history
}
};
@@ -320,7 +314,7 @@ macro_rules! generic_db_accept_edits_batch {
AND {entity}_edit.editgroup_id = $1",
entity = $entity_name_str
)).bind::<diesel::sql_types::Uuid, _>(editgroup_id.to_uuid())
- .execute(conn)?;
+ .execute(conn)?;
Ok(count as u64)
}
};
@@ -444,10 +438,8 @@ impl EntityCrud for ContainerEntity {
abbrev: model.abbrev.clone(),
coden: model.coden.clone(),
extra_json: model.extra.clone(),
- })
- .collect::<Vec<ContainerRevNewRow>>(),
- )
- .returning(container_rev::id)
+ }).collect::<Vec<ContainerRevNewRow>>(),
+ ).returning(container_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}
@@ -521,10 +513,8 @@ impl EntityCrud for CreatorEntity {
orcid: model.orcid.clone(),
wikidata_qid: model.wikidata_qid.clone(),
extra_json: model.extra.clone(),
- })
- .collect::<Vec<CreatorRevNewRow>>(),
- )
- .returning(creator_rev::id)
+ }).collect::<Vec<CreatorRevNewRow>>(),
+ ).returning(creator_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}
@@ -576,8 +566,7 @@ impl EntityCrud for FileEntity {
.map(|r: FileRevUrlRow| FileEntityUrls {
rel: r.rel,
url: r.url,
- })
- .collect();
+ }).collect();
Ok(FileEntity {
sha1: rev_row.sha1,
@@ -608,10 +597,8 @@ impl EntityCrud for FileEntity {
md5: model.md5.clone(),
mimetype: model.mimetype.clone(),
extra_json: model.extra.clone(),
- })
- .collect::<Vec<FileRevNewRow>>(),
- )
- .returning(file_rev::id)
+ }).collect::<Vec<FileRevNewRow>>(),
+ ).returning(file_rev::id)
.get_results(conn)?;
let mut file_release_rows: Vec<FileReleaseRow> = vec![];
@@ -628,8 +615,7 @@ impl EntityCrud for FileEntity {
file_rev: *rev_id,
target_release_ident_id: FatCatId::from_str(r)?.to_uuid(),
})
- })
- .collect();
+ }).collect();
file_release_rows.extend(these_release_rows?);
}
};
@@ -643,8 +629,7 @@ impl EntityCrud for FileEntity {
file_rev: *rev_id,
rel: u.rel.clone(),
url: u.url.clone(),
- })
- .collect();
+ }).collect();
file_url_rows.extend(these_url_rows);
}
};
@@ -746,8 +731,7 @@ impl EntityCrud for ReleaseEntity {
Some(FatCatId::from_uuid(&new_work_ids.pop().unwrap()).to_string())
}
model
- })
- .collect();
+ }).collect();
let model_refs: Vec<&Self> = models_with_work_ids.iter().map(|s| s).collect();
let models = model_refs.as_slice();
@@ -761,10 +745,8 @@ impl EntityCrud for ReleaseEntity {
rev_id: Some(*rev_id),
is_live: edit_context.autoaccept,
redirect_id: None,
- })
- .collect::<Vec<Self::IdentNewRow>>(),
- )
- .returning(release_ident::id)
+ }).collect::<Vec<Self::IdentNewRow>>(),
+ ).returning(release_ident::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = insert_into(release_edit::table)
.values(
@@ -778,10 +760,8 @@ impl EntityCrud for ReleaseEntity {
redirect_id: None,
prev_rev: None,
extra_json: edit_context.extra_json.clone(),
- })
- .collect::<Vec<Self::EditNewRow>>(),
- )
- .get_results(conn)?;
+ }).collect::<Vec<Self::EditNewRow>>(),
+ ).get_results(conn)?;
Ok(edits)
}
@@ -805,29 +785,27 @@ impl EntityCrud for ReleaseEntity {
.get_results(conn)?
.into_iter()
.map(|r: ReleaseRefRow| ReleaseRef {
- index: r.index_val,
+ index: r.index_val.map(|v| v as i64),
key: r.key,
extra: r.extra_json,
- container_title: r.container_title,
- year: r.year,
+ container_name: r.container_name,
+ year: r.year.map(|v| v as i64),
title: r.title,
locator: r.locator,
target_release_id: r
.target_release_ident_id
.map(|v| FatCatId::from_uuid(&v).to_string()),
- })
- .collect();
+ }).collect();
let contribs: Vec<ReleaseContrib> = release_contrib::table
.filter(release_contrib::release_rev.eq(rev_row.id))
.order((
release_contrib::role.asc(),
release_contrib::index_val.asc(),
- ))
- .get_results(conn)?
+ )).get_results(conn)?
.into_iter()
.map(|c: ReleaseContribRow| ReleaseContrib {
- index: c.index_val,
+ index: c.index_val.map(|v| v as i64),
raw_name: c.raw_name,
role: c.role,
extra: c.extra_json,
@@ -835,8 +813,7 @@ impl EntityCrud for ReleaseEntity {
.creator_ident_id
.map(|v| FatCatId::from_uuid(&v).to_string()),
creator: None,
- })
- .collect();
+ }).collect();
let abstracts: Vec<ReleaseEntityAbstracts> = release_rev_abstract::table
.inner_join(abstracts::table)
@@ -850,8 +827,7 @@ impl EntityCrud for ReleaseEntity {
lang: r.0.lang,
content: Some(r.1.content),
},
- )
- .collect();
+ ).collect();
Ok(ReleaseEntity {
title: rev_row.title,
@@ -961,16 +937,15 @@ impl EntityCrud for ReleaseEntity {
None => None,
Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()),
},
- index_val: r.index,
+ index_val: r.index.map(|v| v as i32),
key: r.key.clone(),
- container_title: r.container_title.clone(),
- year: r.year,
+ container_name: r.container_name.clone(),
+ year: r.year.map(|v| v as i32),
title: r.title.clone(),
locator: r.locator.clone(),
extra_json: r.extra.clone(),
})
- })
- .collect::<Result<Vec<ReleaseRefNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseRefNewRow>>>()?;
release_ref_rows.extend(these_ref_rows);
}
};
@@ -988,12 +963,11 @@ impl EntityCrud for ReleaseEntity {
Some(v) => Some(FatCatId::from_str(&v)?.to_uuid()),
},
raw_name: c.raw_name.clone(),
- index_val: c.index,
+ index_val: c.index.map(|v| v as i32),
role: c.role.clone(),
extra_json: c.extra.clone(),
})
- })
- .collect::<Result<Vec<ReleaseContribNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseContribNewRow>>>()?;
release_contrib_rows.extend(these_contrib_rows);
}
};
@@ -1007,8 +981,7 @@ impl EntityCrud for ReleaseEntity {
.map(|c| AbstractsRow {
sha1: Sha1::from(c.content.clone().unwrap()).hexdigest(),
content: c.content.clone().unwrap(),
- })
- .collect();
+ }).collect();
abstract_rows.extend(new_abstracts);
let new_release_abstract_rows: Vec<ReleaseRevAbstractNewRow> = abstract_list
.into_iter()
@@ -1025,8 +998,7 @@ impl EntityCrud for ReleaseEntity {
lang: c.lang.clone(),
mimetype: c.mimetype.clone(),
})
- })
- .collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
+ }).collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
release_abstract_rows.extend(new_release_abstract_rows);
}
}
@@ -1108,10 +1080,8 @@ impl EntityCrud for WorkEntity {
.iter()
.map(|model| WorkRevNewRow {
extra_json: model.extra.clone(),
- })
- .collect::<Vec<WorkRevNewRow>>(),
- )
- .returning(work_rev::id)
+ }).collect::<Vec<WorkRevNewRow>>(),
+ ).returning(work_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}