From e1b3c521341fcebaf5486e0af36ea15b14c40a4a Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 19:26:45 -0700 Subject: hack around JSON serialization for now --- rust/src/api_server.rs | 24 +++++++++++++++++++----- rust/src/database_models.rs | 5 +++-- rust/src/lib.rs | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 9fbcbc57..b8ec3abd 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -35,26 +35,40 @@ impl Api for Server { ) -> Box + Send> { let conn = self.db_pool.get().expect("db_pool error"); let id = uuid::Uuid::parse_str(&id).unwrap(); + let (ident, rev): (ContainerIdentRow, Option) = container_ident::table + .find(id) + .left_outer_join(container_rev::table) + .first(&conn) + .expect("error loading container"); +/* + let (ident, rev): (ContainerIdentRow, Option) = container_ident::table + .left_join(container_rev::table) + .filter(container_ident::id.equals(id)) + .first(&conn) + .expect("error loading container"); +*/ +/* let c: ContainerIdentRow = container_ident::table .find(id) .first(&conn) .expect("error loading container"); //let c: i64 = container_rev::table.count().first(&conn).expect("DB Error"); println!("container count: {:?}", c); +*/ - let ce = ContainerEntity { + let entity = ContainerEntity { issn: None, publisher: Some("Hello!".into()), parent: None, name: None, state: None, - ident: Some(c.id.to_string()), - revision: c.rev_id.map(|v| v as isize), - redirect: None, + ident: Some(ident.id.to_string()), + revision: ident.rev_id.map(|v| v as isize), + redirect: ident.redirect_id.map(|u| u.to_string()), editgroup: None, }; Box::new(futures::done(Ok( - ContainerIdGetResponse::FetchASingleContainerById(ce), + ContainerIdGetResponse::FetchASingleContainerById(entity), ))) } diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index 7153d18f..6c899ccf 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -1,5 +1,6 @@ use chrono; +use serde_json; use uuid::Uuid; //use diesel::prelude::*; @@ -20,7 +21,7 @@ macro_rules! entity_structs { pub rev_id: Option, pub redirect_id: Option, pub editgroup_id: i64, - //pub extra_json: Option, + //pub extra_json: Option, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] @@ -38,7 +39,7 @@ macro_rules! entity_structs { #[table_name = "container_rev"] pub struct ContainerRevRow { pub id: i64, - //extra_json: Option, + //pub extra_json: Option, pub name: String, pub parent_ident_id: Option, pub publisher: Option, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 196dee36..49d0ef70 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -13,6 +13,7 @@ extern crate hyper; extern crate error_chain; extern crate iron; extern crate r2d2; +extern crate serde_json; pub mod api_server; pub mod database_schema; -- cgit v1.2.3