From 3df7af7032db4f4ea9c5f08612e8b4dd1ee38efb Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Thu, 16 Jul 2020 00:48:41 -0400 Subject: [PATCH] Easier to read handler reply style --- src/main.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index c2d77f8..3b6f473 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,21 +177,25 @@ mod handlers { pub async fn get_shop(env: Environment, id: i32) -> Result { let shop = Shop::get(&env.db, id).await.map_err(reject_anyhow)?; - return Ok(with_status(json(&shop), StatusCode::OK)); + let reply = json(&shop); + let reply = with_status(reply, StatusCode::OK); + Ok(reply) } pub async fn create_shop(env: Environment, shop: Shop) -> Result { let saved_shop = shop.save(&env.db).await.map_err(reject_anyhow)?; let url = saved_shop.url(&env.api_url).map_err(reject_anyhow)?; - return Ok(with_status( - with_header(json(&saved_shop), "Location", url.as_str()), - StatusCode::CREATED, - )); + let reply = json(&saved_shop); + let reply = with_header(reply, "Location", url.as_str()); + let reply = with_status(reply, StatusCode::CREATED); + Ok(reply) } pub async fn get_owner(env: Environment, id: i32) -> Result { let owner = Owner::get(&env.db, id).await.map_err(reject_anyhow)?; - return Ok(with_status(json(&owner), StatusCode::OK)); + let reply = json(&owner); + let reply = with_status(reply, StatusCode::OK); + Ok(reply) } pub async fn create_owner( @@ -208,10 +212,10 @@ mod handlers { }; let saved_owner = owner_with_ip.save(&env.db).await.map_err(reject_anyhow)?; let url = saved_owner.url(&env.api_url).map_err(reject_anyhow)?; - return Ok(with_status( - with_header(json(&saved_owner), "Location", url.as_str()), - StatusCode::CREATED, - )); + let reply = json(&saved_owner); + let reply = with_header(reply, "Location", url.as_str()); + let reply = with_status(reply, StatusCode::CREATED); + Ok(reply) } }