aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 14:45:42 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 14:45:42 -0700
commitfe77445bd16db003e03b5c44fa02c65b78e6fa02 (patch)
tree7411bbbaecf4c086c97746fa1845dc0169b33438 /rust/src/api_server.rs
parent85d469196ff17a3aee7a950ae57d4797938e8f42 (diff)
downloadfatcat-fe77445bd16db003e03b5c44fa02c65b78e6fa02.tar.gz
fatcat-fe77445bd16db003e03b5c44fa02c65b78e6fa02.zip
working db_pool and response
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs41
1 files changed, 25 insertions, 16 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 77ac324b..3da38724 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -7,13 +7,18 @@ use futures::{self, Future};
use std::collections::HashMap;
+use ConnectionPool;
use self::models::*;
use diesel;
+use r2d2;
use diesel::prelude::*;
use iron_diesel_middleware::DieselPooledConnection;
+use r2d2_diesel::ConnectionManager;
use swagger;
+use database_schema::creator_rev::table as container_rev;
+
use fatcat_api::models;
use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse,
ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse,
@@ -23,8 +28,11 @@ use fatcat_api::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetRespon
FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse,
ReleasePostResponse, WorkIdGetResponse, WorkPostResponse};
-#[derive(Copy, Clone)]
-pub struct Server;
+//#[derive(Copy, Clone)]
+#[derive(Clone)]
+pub struct Server {
+ pub db_pool: ConnectionPool,
+}
impl Api for Server {
fn container_id_get(
@@ -32,20 +40,21 @@ impl Api for Server {
id: String,
context: &Context,
) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> {
- let context = context.clone();
- //let con: DieselPooledConnection<diesel::pg::PgConnection> = req.db_conn();
- println!(
- "container_id_get(\"{}\") - X-Span-ID: {:?}",
- id,
- context.x_span_id.unwrap_or(String::from("<none>")).clone()
- );
- /*
- println!(
- "container count: {}",
- containers.count().load(&con).expect("DB Error"),
- );
- */
- Box::new(futures::failed("Generic failure".into()))
+ 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 ce = ContainerEntity{
+ issn: None,
+ publisher: Some("Hello!".into()),
+ parent: None,
+ name: None,
+ state: None,
+ ident: None,
+ revision: None,
+ redirect: None,
+ editgroup: None,
+ };
+ Box::new(futures::done(Ok(ContainerIdGetResponse::FetchASingleContainerById(ce))))
}
fn container_lookup_get(