aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 21:18:01 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 21:18:01 -0700
commit6e96f5e6e409f2bf2c389c7315f0747ab9e24d00 (patch)
tree7f866c38eb5f8a257da9e255029032f6b173c1d3 /rust/src
parent0ed087be71b02d9279bd3b131131eae672580d71 (diff)
downloadfatcat-6e96f5e6e409f2bf2c389c7315f0747ab9e24d00.tar.gz
fatcat-6e96f5e6e409f2bf2c389c7315f0747ab9e24d00.zip
fmt
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_server.rs42
-rw-r--r--rust/src/database_models.rs30
-rw-r--r--rust/src/lib.rs4
3 files changed, 38 insertions, 38 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 81232728..8523f154 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -2,17 +2,12 @@
use ConnectionPool;
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,
- editor, editgroup, changelog
-};
-use uuid;
+use database_schema::{changelog, container_edit, container_ident, container_rev, creator_edit,
+ creator_ident, creator_rev, editgroup, editor, file_edit, file_ident,
+ file_rev, release_edit, release_ident, release_rev, work_edit, work_ident,
+ work_rev};
use diesel::prelude::*;
use diesel::{self, insert_into};
-use futures::{self, Future};
use fatcat_api::models;
use fatcat_api::models::*;
use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse,
@@ -22,6 +17,8 @@ use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetRespon
EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse,
FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse,
ReleasePostResponse, WorkIdGetResponse, WorkPostResponse};
+use futures::{self, Future};
+use uuid;
#[derive(Clone)]
pub struct Server {
@@ -36,6 +33,7 @@ impl Api for Server {
) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
let id = uuid::Uuid::parse_str(&id).unwrap();
+
let (ident, rev): (ContainerIdentRow, ContainerRevRow) = container_ident::table
.find(id)
.inner_join(container_rev::table)
@@ -45,9 +43,9 @@ impl Api for Server {
let entity = ContainerEntity {
issn: rev.issn,
publisher: rev.publisher,
- parent: None, // TODO
+ parent: None, // TODO
name: Some(rev.name), // TODO: not optional
- state: None, // TODO:
+ state: None, // TODO:
ident: Some(ident.id.to_string()),
revision: ident.rev_id.map(|v| v as isize),
redirect: ident.redirect_id.map(|u| u.to_string()),
@@ -79,7 +77,7 @@ impl Api for Server {
) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
println!("{:?}", body);
let body = body.expect("missing body"); // TODO: required parameter
- //let editgroup_id: i64 = body.editgroup.expect("need editgroup_id") as i64; // TODO: or find/create
+ //let editgroup_id: i64 = body.editgroup.expect("need editgroup_id") as i64; // TODO: or find/create
let editgroup_id = 1;
let conn = self.db_pool.get().expect("db_pool error");
@@ -96,8 +94,8 @@ impl Api for Server {
RETURNING id )
INSERT INTO container_edit (editgroup_id, ident_id, rev_id) VALUES
($3, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev))
- RETURNING *")
- .bind::<diesel::sql_types::Text, _>(name)
+ RETURNING *",
+ ).bind::<diesel::sql_types::Text, _>(name)
.bind::<diesel::sql_types::Text, _>(issn)
.bind::<diesel::sql_types::BigInt, _>(editgroup_id)
.load(&conn)
@@ -110,9 +108,9 @@ impl Api for Server {
ident: Some(edit.ident_id.to_string()),
id: Some(edit.id as isize),
};
- Box::new(futures::done(Ok(
- ContainerPostResponse::Created(entity_edit),
- )))
+ Box::new(futures::done(Ok(ContainerPostResponse::Created(
+ entity_edit,
+ ))))
}
fn creator_id_get(
@@ -121,16 +119,6 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> {
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,
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index e95e5980..0995304f 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -1,16 +1,14 @@
-
use chrono;
//use serde_json;
-use uuid::Uuid;
use database_schema::*;
+use uuid::Uuid;
// Ugh. I thought the whole point was to *not* do this, but:
// https://github.com/diesel-rs/diesel/issues/1589
// Helper for constructing tables
macro_rules! entity_structs {
- ($edit_table:expr, $edit_struct:ident, $ident_table:expr, $ident_struct:ident) => (
-
+ ($edit_table:expr, $edit_struct:ident, $ident_table:expr, $ident_struct:ident) => {
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset, QueryableByName)]
#[table_name = $edit_table]
pub struct $edit_struct {
@@ -30,7 +28,7 @@ macro_rules! entity_structs {
pub rev_id: Option<i64>,
pub redirect_id: Option<Uuid>,
}
- )
+ };
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
@@ -44,7 +42,12 @@ pub struct ContainerRevRow {
pub issn: Option<String>,
}
-entity_structs!("container_edit", ContainerEditRow, "container_ident", ContainerIdentRow);
+entity_structs!(
+ "container_edit",
+ ContainerEditRow,
+ "container_ident",
+ ContainerIdentRow
+);
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "creator_rev"]
@@ -55,7 +58,12 @@ pub struct CreatorRevRow {
pub orcid: Option<String>,
}
-entity_structs!("creator_edit", CreatorEditRow, "creator_ident", CreatorIdentRow);
+entity_structs!(
+ "creator_edit",
+ CreatorEditRow,
+ "creator_ident",
+ CreatorIdentRow
+);
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "file_rev"]
@@ -86,7 +94,12 @@ pub struct ReleaseRevRow {
pub issue: Option<String>,
}
-entity_structs!("release_edit", ReleaseEditRow, "release_ident", ReleaseIdentRow);
+entity_structs!(
+ "release_edit",
+ ReleaseEditRow,
+ "release_ident",
+ ReleaseIdentRow
+);
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "work_rev"]
@@ -109,7 +122,6 @@ pub struct ReleaseContribRow {
contrib_type: Option<String>,
}
-
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "release_ref"]
pub struct ReleaseRefRow {
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 49d0ef70..b59d6024 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -3,9 +3,9 @@ extern crate fatcat_api;
extern crate chrono;
#[macro_use]
extern crate diesel;
-extern crate uuid;
extern crate dotenv;
extern crate futures;
+extern crate uuid;
#[macro_use]
extern crate hyper;
//extern crate swagger;
@@ -16,8 +16,8 @@ extern crate r2d2;
extern crate serde_json;
pub mod api_server;
-pub mod database_schema;
pub mod database_models;
+pub mod database_schema;
mod errors {
error_chain!{}