summaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index aaf3d9a7..efe40165 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -129,6 +129,31 @@ macro_rules! wrap_lookup_handler {
}
}
+macro_rules! wrap_history_handler {
+ ($get_fn:ident, $get_handler:ident, $get_resp:ident) => {
+ fn $get_fn(
+ &self,
+ id: String,
+ limit: Option<i64>,
+ _context: &Context,
+ ) -> Box<Future<Item = $get_resp, Error = ApiError> + Send> {
+ let ret = match self.$get_handler(id.clone(), limit) {
+ Ok(history) =>
+ $get_resp::FoundEntityHistory(history),
+ Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) =>
+ $get_resp::NotFound(ErrorResponse { message: format!("No such entity {}: {}", stringify!($model), id) }),
+ Err(Error(ErrorKind::Uuid(e), _)) =>
+ $get_resp::BadRequest(ErrorResponse { message: e.to_string() }),
+ Err(e) => {
+ error!("{}", e);
+ $get_resp::GenericError(ErrorResponse { message: e.to_string() })
+ },
+ };
+ Box::new(futures::done(Ok(ret)))
+ }
+ }
+}
+
macro_rules! count_entity {
($table:ident, $conn:expr) => {{
let count: i64 = $table::table
@@ -350,6 +375,32 @@ impl Server {
container_row2entity(Some(ident), rev)
}
+ fn get_container_history_handler(
+ &self,
+ id: String,
+ limit: Option<i64>,
+ ) -> Result<Vec<EntityHistoryEntry>> {
+ let conn = self.db_pool.get().expect("db_pool error");
+ let id = uuid::Uuid::parse_str(&id)?;
+ let limit = limit.unwrap_or(50);
+
+ let rows: Vec<(EditgroupRow, ChangelogRow, ContainerEditRow)> = editgroup::table
+ .inner_join(changelog::table)
+ .inner_join(container_edit::table)
+ .filter(container_edit::ident_id.eq(id))
+ .limit(limit)
+ .get_results(&conn)?;
+
+ let history: Vec<EntityHistoryEntry> = rows.into_iter()
+ .map(|(eg_row, cl_row, ce_row)| EntityHistoryEntry {
+ edit: ce_row.to_model().expect("edit row to model"),
+ editgroup: eg_row.to_model_partial(),
+ changelog_entry: cl_row.to_model(),
+ })
+ .collect();
+ Ok(history)
+ }
+
fn get_creator_handler(&self, id: String) -> Result<CreatorEntity> {
let conn = self.db_pool.get().expect("db_pool error");
let id = uuid::Uuid::parse_str(&id)?;
@@ -1084,6 +1135,11 @@ impl Api for Server {
doi,
String
);
+ wrap_history_handler!(
+ get_container_history,
+ get_container_history_handler,
+ GetContainerHistoryResponse
+ );
// Rename "wrap_lookup_handler"?
wrap_lookup_handler!(