aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/database_models.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/database_models.rs')
-rw-r--r--rust/src/database_models.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index 9913b7e2..b46d6ffb 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -3,6 +3,7 @@ use database_schema::*;
use errors::*;
use serde_json;
use uuid::Uuid;
+use fatcat_api::models::EntityEdit;
// Ugh. I thought the whole point was to *not* do this, but:
// https://github.com/diesel-rs/diesel/issues/1589
@@ -29,6 +30,10 @@ pub trait EntityIdentRow {
fn state(&self) -> Result<EntityState>;
}
+pub trait EntityEditRow {
+ fn to_model(self) -> Result<EntityEdit>;
+}
+
// Helper for constructing tables
macro_rules! entity_structs {
($edit_table:expr, $edit_struct:ident, $ident_table:expr, $ident_struct:ident) => {
@@ -43,6 +48,20 @@ macro_rules! entity_structs {
pub extra_json: Option<serde_json::Value>,
}
+ impl EntityEditRow for $edit_struct {
+ /// Go from a row (SQL model) to an API model
+ fn to_model(self) -> Result<EntityEdit> {
+ Ok(EntityEdit {
+ editgroup_id: self.editgroup_id,
+ revision: self.rev_id,
+ redirect_ident: self.redirect_id.map(|v| v.to_string()),
+ ident: self.ident_id.to_string(),
+ edit_id: self.id,
+ extra: self.extra_json,
+ })
+ }
+ }
+
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = $ident_table]
pub struct $ident_struct {