summaryrefslogtreecommitdiffstats
path: root/rust/src/database_models.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-06-30 17:34:22 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-06-30 17:34:22 -0700
commitf4064c19ec140987e15c64e80a3bf0c70025b31b (patch)
treee89548d5d5f350f65e9c294a34c71a2225a14099 /rust/src/database_models.rs
parent3ed7db573438d3620d295813a81237acb91155cb (diff)
downloadfatcat-f4064c19ec140987e15c64e80a3bf0c70025b31b.tar.gz
fatcat-f4064c19ec140987e15c64e80a3bf0c70025b31b.zip
history for container entities
Diffstat (limited to 'rust/src/database_models.rs')
-rw-r--r--rust/src/database_models.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index dd84748d..6fa9b7b7 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -1,7 +1,7 @@
use chrono;
use database_schema::*;
use errors::*;
-use fatcat_api::models::EntityEdit;
+use fatcat_api::models::{ChangelogEntry, Editgroup, EntityEdit};
use serde_json;
use uuid::Uuid;
@@ -243,6 +243,20 @@ pub struct EditgroupRow {
pub description: Option<String>,
}
+impl EditgroupRow {
+ /// Returns an Edigroup API model *without* the entity edits actually populated. Useful for,
+ /// eg, entity history queries (where we already have the entity edit we want)
+ pub fn to_model_partial(self) -> Editgroup {
+ Editgroup {
+ id: Some(self.id),
+ editor_id: self.editor_id,
+ description: self.description,
+ extra: self.extra_json,
+ edits: None,
+ }
+ }
+}
+
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "editor"]
pub struct EditorRow {
@@ -259,3 +273,13 @@ pub struct ChangelogRow {
pub editgroup_id: i64,
pub timestamp: chrono::NaiveDateTime,
}
+
+impl ChangelogRow {
+ pub fn to_model(self) -> ChangelogEntry {
+ ChangelogEntry {
+ index: self.id,
+ editgroup_id: self.editgroup_id,
+ timestamp: chrono::DateTime::from_utc(self.timestamp, chrono::Utc),
+ }
+ }
+}