summaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 18:12:32 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 18:12:39 -0700
commit2b4d62b086802ece28f1288bd09cbf5f252c45d7 (patch)
tree6d82c1fe431c3456566eca7590e024e4c970d049 /rust/src/api_server.rs
parent69e9497686a05c8b27d5496e5ff66664c785c25b (diff)
downloadfatcat-2b4d62b086802ece28f1288bd09cbf5f252c45d7.tar.gz
fatcat-2b4d62b086802ece28f1288bd09cbf5f252c45d7.zip
progress on database lookup
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs59
1 files changed, 42 insertions, 17 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index d9273186..aa13023d 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -1,13 +1,16 @@
//! API endpoint handlers
use ConnectionPool;
-use database_schema::container_rev::table as container_rev;
+use database_models::*;
+use database_schema::{container_rev, container_ident, container_edit,
+ creator_rev, creator_ident, creator_edit,
+ file_rev, file_ident, file_edit,
+ release_rev, release_ident, release_edit,
+ work_rev, work_ident, work_edit,
+};
+use uuid;
use diesel::prelude::*;
use futures::{self, Future};
-//use database_schema::creator_rev::table as creator_rev;
-//use database_schema::file_rev::table as file_rev;
-//use database_schema::release_rev::table as release_rev;
-//use database_schema::work_rev::table as work_rev;
use fatcat_api::models;
use fatcat_api::models::*;
use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse,
@@ -26,20 +29,26 @@ pub struct Server {
impl Api for Server {
fn container_id_get(
&self,
- _id: String,
+ id: String,
_context: &Context,
) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let c: i64 = container_rev.count().first(&*conn).expect("DB Error");
- println!("container count: {}", c);
+ let id = uuid::Uuid::parse_str(&id).unwrap();
+ 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 {
issn: None,
publisher: Some("Hello!".into()),
parent: None,
name: None,
state: None,
- ident: None,
- revision: None,
+ ident: Some(c.id.to_string()),
+ revision: c.rev_id.map(|v| v as isize),
redirect: None,
editgroup: None,
};
@@ -81,13 +90,29 @@ impl Api for Server {
id: String,
context: &Context,
) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> {
- let context = context.clone();
- println!(
- "creator_id_get(\"{}\") - X-Span-ID: {:?}",
- id,
- context.x_span_id.unwrap_or(String::from("<none>")).clone()
- );
- Box::new(futures::failed("Generic failure".into()))
+ let conn = self.db_pool.get().expect("db_pool error");
+ /*
+ let first_thing: (Uuid, bool, Option<i64>, Option<Uuid>) = creator_ident::table
+ .first(&conn)
+ .unwrap();
+ let entity_table = creator_ident::table.left_join(creator_rev::table);
+ let thing: (creator_ident::SqlType, creator_rev::SqlType) = creator_ident::table
+ .inner_join(creator_rev::table)
+ .first(&conn)
+ .expect("Error loading creator");
+ */
+ let ce = CreatorEntity {
+ orcid: None,
+ name: None,
+ state: None,
+ ident: None,
+ revision: None,
+ redirect: None,
+ editgroup: None,
+ };
+ Box::new(futures::done(Ok(
+ CreatorIdGetResponse::FetchASingleCreatorById(ce),
+ )))
}
fn creator_lookup_get(