diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-23 18:27:04 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-24 15:21:32 -0700 |
commit | 11b1c4359779b4c9a7437af53028430f8372b287 (patch) | |
tree | aa6e70dbcb0b05d68e4c611285b439b654800cc3 /rust/src | |
parent | b335a14b08860499129e513ce274b640e5fbb11e (diff) | |
download | fatcat-11b1c4359779b4c9a7437af53028430f8372b287.tar.gz fatcat-11b1c4359779b4c9a7437af53028430f8372b287.zip |
rust fmt
Diffstat (limited to 'rust/src')
-rw-r--r-- | rust/src/api_server.rs | 94 | ||||
-rw-r--r-- | rust/src/bin/fatcatd.rs | 18 |
2 files changed, 84 insertions, 28 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 679f2ad8..7df67cee 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -298,7 +298,7 @@ impl Server { issue: rev.issue, container_id: None, // TODO work_id: rev.work_ident_id.to_string(), - 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()), @@ -333,7 +333,7 @@ impl Server { issue: rev.issue, container_id: None, // TODO work_id: rev.work_ident_id.to_string(), - 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()), @@ -390,21 +390,64 @@ impl Server { .collect(); Ok(Some(entries)) } - } impl Api for Server { - wrap_get_id_handler!(container_id_get, container_id_get_handler, ContainerIdGetResponse, String); - wrap_get_id_handler!(creator_id_get, creator_id_get_handler, CreatorIdGetResponse, String); + wrap_get_id_handler!( + container_id_get, + container_id_get_handler, + ContainerIdGetResponse, + String + ); + wrap_get_id_handler!( + creator_id_get, + creator_id_get_handler, + CreatorIdGetResponse, + String + ); wrap_get_id_handler!(file_id_get, file_id_get_handler, FileIdGetResponse, String); wrap_get_id_handler!(work_id_get, work_id_get_handler, WorkIdGetResponse, String); - wrap_get_id_handler!(release_id_get, release_id_get_handler, ReleaseIdGetResponse, String); - wrap_get_id_handler!(editgroup_id_get, editgroup_id_get_handler, EditgroupIdGetResponse, i32); - - wrap_lookup_handler!(container_lookup_get, container_lookup_get_handler, ContainerLookupGetResponse, issn, String); - wrap_lookup_handler!(creator_lookup_get, creator_lookup_get_handler, CreatorLookupGetResponse, orcid, String); - wrap_lookup_handler!(file_lookup_get, file_lookup_get_handler, FileLookupGetResponse, sha1, String); - wrap_lookup_handler!(release_lookup_get, release_lookup_get_handler, ReleaseLookupGetResponse, doi, String); + wrap_get_id_handler!( + release_id_get, + release_id_get_handler, + ReleaseIdGetResponse, + String + ); + wrap_get_id_handler!( + editgroup_id_get, + editgroup_id_get_handler, + EditgroupIdGetResponse, + i32 + ); + + wrap_lookup_handler!( + container_lookup_get, + container_lookup_get_handler, + ContainerLookupGetResponse, + issn, + String + ); + wrap_lookup_handler!( + creator_lookup_get, + creator_lookup_get_handler, + CreatorLookupGetResponse, + orcid, + String + ); + wrap_lookup_handler!( + file_lookup_get, + file_lookup_get_handler, + FileLookupGetResponse, + sha1, + String + ); + wrap_lookup_handler!( + release_lookup_get, + release_lookup_get_handler, + ReleaseLookupGetResponse, + doi, + String + ); fn container_post( &self, @@ -503,7 +546,9 @@ impl Api for Server { INSERT INTO file_edit (editgroup_id, ident_id, rev_id) VALUES ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Int4>, _>(body.size.map(|v| v as i32)) + ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Int4>, _>( + body.size.map(|v| v as i32), + ) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.sha1) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.url) .bind::<diesel::sql_types::BigInt, _>(editgroup_id) @@ -532,8 +577,9 @@ impl Api for Server { let editgroup_id = 1; let conn = self.db_pool.get().expect("db_pool error"); - let edit: WorkEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO work_rev (work_type) + let edit: WorkEditRow = + diesel::sql_query( + "WITH rev AS ( INSERT INTO work_rev (work_type) VALUES ($1) RETURNING id ), ident AS ( INSERT INTO work_ident (rev_id) @@ -542,10 +588,10 @@ impl Api for Server { INSERT INTO work_edit (editgroup_id, ident_id, rev_id) VALUES ($2, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.work_type) - .bind::<diesel::sql_types::BigInt, _>(editgroup_id) - .get_result(&conn) - .unwrap(); + ).bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(body.work_type) + .bind::<diesel::sql_types::BigInt, _>(editgroup_id) + .get_result(&conn) + .unwrap(); let edit = &edit; let entity_edit = EntityEdit { @@ -634,8 +680,8 @@ impl Api for Server { let row: EditgroupRow = insert_into(editgroup::table) .values(( editgroup::editor_id.eq(body.editor_id as i64), - editgroup::description.eq(body.description) - )) + editgroup::description.eq(body.description), + )) .get_result(&conn) .expect("error creating edit group"); @@ -644,9 +690,9 @@ impl Api for Server { editor_id: row.editor_id as isize, description: row.description, }; - Box::new(futures::done(Ok(EditgroupPostResponse::SuccessfullyCreated( - new_eg, - )))) + Box::new(futures::done(Ok( + EditgroupPostResponse::SuccessfullyCreated(new_eg), + ))) } fn editor_username_changelog_get( diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs index d4bc2683..53df7f71 100644 --- a/rust/src/bin/fatcatd.rs +++ b/rust/src/bin/fatcatd.rs @@ -17,8 +17,8 @@ extern crate slog_async; extern crate slog_term; use clap::{App, Arg}; -use iron::{Chain, Iron, IronResult, Response, Request, status, Url}; use iron::modifiers::RedirectRaw; +use iron::{status, Chain, Iron, IronResult, Request, Response, Url}; use iron_slog::{DefaultLogFormatter, LoggerMiddleware}; use slog::{Drain, Logger}; //use dotenv::dotenv; @@ -51,14 +51,24 @@ fn main() { fn root_handler(_: &mut Request) -> IronResult<Response> { //Ok(Response::with((status::Found, Redirect(Url::parse("/swagger-ui").unwrap())))) - Ok(Response::with((status::Found, RedirectRaw("/swagger-ui".to_string())))) + Ok(Response::with(( + status::Found, + RedirectRaw("/swagger-ui".to_string()), + ))) } fn swaggerui_handler(_: &mut Request) -> IronResult<Response> { let html_type = "text/html".parse::<iron::mime::Mime>().unwrap(); - Ok(Response::with((html_type, status::Ok, include_str!("../../swagger-ui/index.html")))) + Ok(Response::with(( + html_type, + status::Ok, + include_str!("../../swagger-ui/index.html"), + ))) } fn yaml_handler(_: &mut Request) -> IronResult<Response> { - Ok(Response::with((status::Ok, include_str!("../../fatcat-openapi2.yml")))) + Ok(Response::with(( + status::Ok, + include_str!("../../fatcat-openapi2.yml"), + ))) } let mut chain = Chain::new(LoggerMiddleware::new(router, logger, formatter)); |