From d1cfc4284c458d0bedecda3960e8ec02aae31352 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 2 Jun 2020 03:25:11 -0700 Subject: [PATCH] child calls from main_responder (see route_dipatcher + route handlers) now borrow a connection for the sql db --- server/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index b6a134b..b8bd142 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -23,6 +23,7 @@ mod auth; use auth::AuthReason; mod routes; +mod invites; fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> { /* @@ -42,9 +43,9 @@ fn map_qs(query_string_raw: Option<&str>) -> HashMap<&str, &str> { map } -async fn route_dispatcher(resp: &mut Response, meth: &Method, path: &str, params: &HashMap<&str, &str>) { +async fn route_dispatcher(conn: &Conn, resp: &mut Response, meth: &Method, path: &str, params: &HashMap<&str, &str>) { match (meth, path) { - (&Method::GET, routes::INVITE_JOIN) => invites::join_invite_code(&mut resp, meth, path, params), + (&Method::GET, routes::INVITE_JOIN) => invites::join_invite_code(conn, &mut resp, params).await, _ => { *resp.status_mut() = StatusCode::NOT_FOUND; } @@ -61,7 +62,7 @@ async fn main_responder(request: Request) -> Result, hyper: if let Ok(conn) = Conn::from_url(env::var("DATABASE_URL").unwrap()).await { // some more information in the response would be great right about here match auth::wall_entry(path, conn, ¶ms).await { - OpenAuth | Good => route_dispatcher(&mut response, &method, path, ¶ms).await, + OpenAuth | Good => route_dispatcher(&conn, &mut response, &method, path, ¶ms).await, LimitPassed => *response.status_mut() = StatusCode::UNAUTHORIZED, NoKey => *response.status_mut() = StatusCode::UNAUTHORIZED, InternalFailure => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR