aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/database_models.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-26 19:58:54 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-26 19:58:54 -0700
commit27052a8e1332669e23d0f36b6aad9cd324c9ec51 (patch)
treeac47f21111a01f4ebadcd6e271945f349c84c742 /rust/src/database_models.rs
parenteb989d60e086384500f3a4712260f81bc61232d3 (diff)
downloadfatcat-27052a8e1332669e23d0f36b6aad9cd324c9ec51.tar.gz
fatcat-27052a8e1332669e23d0f36b6aad9cd324c9ec51.zip
even more refactoring
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 {