From 4a0de5666408f071fb8aee37081da1511e2e3aae Mon Sep 17 00:00:00 2001 From: rascul Date: Sun, 24 Jul 2022 10:52:43 -0500 Subject: [PATCH] use the render_error! macro --- src/routes/help.rs | 13 ++++++------- src/routes/index.rs | 15 ++++++--------- src/routes/replay.rs | 9 +++++---- src/routes/submit/submit_get.rs | 15 ++++++--------- src/routes/submit/submit_post.rs | 4 ++-- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/routes/help.rs b/src/routes/help.rs index 44ad13e..490532f 100644 --- a/src/routes/help.rs +++ b/src/routes/help.rs @@ -1,11 +1,10 @@ -use actix_web::{get, web, HttpResponse}; +use actix_web::{Error, get, web, HttpResponse}; use handlebars::Handlebars; -use serde_json::json; +use serde_json::Value; -#[get("/help")] -pub async fn get(hb: web::Data>) -> HttpResponse { - let data = json!({}); - let body = hb.render("help", &data).unwrap(); +use crate::render_error; - HttpResponse::Ok().body(body) +#[get("/help")] +pub async fn get(hb: web::Data>) -> Result { + Ok(HttpResponse::Ok().body(render_error!(hb, hb.render("help", &Value::Null)))) } diff --git a/src/routes/index.rs b/src/routes/index.rs index 8421512..7c3fab6 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -1,13 +1,10 @@ -use actix_web::{get, web, HttpResponse}; +use actix_web::{get, web, Error, HttpResponse}; use handlebars::Handlebars; -use serde_json::json; +use serde_json::Value; -#[get("/")] -pub async fn get(hb: web::Data>) -> HttpResponse { - let data = json!({ - "name": "rewot" - }); - let body = hb.render("index", &data).unwrap(); +use crate::render_error; - HttpResponse::Ok().body(body) +#[get("/")] +pub async fn get(hb: web::Data>) -> Result { + Ok(HttpResponse::Ok().body(render_error!(hb, hb.render("index", &Value::Null)))) } diff --git a/src/routes/replay.rs b/src/routes/replay.rs index 59d20be..a781f30 100644 --- a/src/routes/replay.rs +++ b/src/routes/replay.rs @@ -9,7 +9,7 @@ use handlebars::Handlebars; use log::info; use serde_json::json; -use crate::Result; +use crate::{render_error, Result}; /// load up and play the replay #[get("/+{id}")] @@ -17,16 +17,17 @@ pub async fn get(id: Path, hb: Data>) -> Result>) -> HttpResponse { - let data = json!({ - "name": "rewot" - }); - let body = hb.render("submit", &data).unwrap(); +use crate::render_error; - HttpResponse::Ok().body(body) +#[get("/submit")] +pub async fn get(hb: web::Data>) -> Result { + Ok(HttpResponse::Ok().body(render_error!(hb, hb.render("submit", &Value::Null)))) } diff --git a/src/routes/submit/submit_post.rs b/src/routes/submit/submit_post.rs index 24de817..81e8eb9 100644 --- a/src/routes/submit/submit_post.rs +++ b/src/routes/submit/submit_post.rs @@ -2,7 +2,7 @@ use actix_multipart::Multipart; use actix_web::{post, web, Error, HttpResponse}; use handlebars::Handlebars; -use serde_json::{json, to_string_pretty}; +use serde_json::to_string_pretty; use crate::render_error; use crate::WotLog; @@ -17,7 +17,7 @@ pub async fn post( render_error!(hb, wotlog.parse_log()); render_error!(hb, wotlog.save()); - let body = format!("{}", render_error!(hb, to_string_pretty(&wotlog.json))); + let body = render_error!(hb, to_string_pretty(&wotlog.json)); Ok(HttpResponse::Ok().body(body)) }