diff --git a/src/database/database.rs b/src/database/database.rs index df86541d..f3b1f402 100644 --- a/src/database/database.rs +++ b/src/database/database.rs @@ -1,11 +1,12 @@ -use diesel::prelude::*; use diesel::pg::PgConnection; +use diesel::prelude::*; use dotenv::dotenv; use std::env; -pub fn connect() -> PgConnection{ +pub fn connect() -> PgConnection { dotenv().ok(); let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!"); - PgConnection::establish(&database_url).unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) + PgConnection::establish(&database_url) + .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) } diff --git a/src/database/mod.rs b/src/database/mod.rs index f9674f87..921a03eb 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -3,4 +3,4 @@ mod models; pub use database::connect; pub use models::Mod; -pub use models::Version; \ No newline at end of file +pub use models::Version; diff --git a/src/database/models.rs b/src/database/models.rs index 6cc48c14..93305650 100644 --- a/src/database/models.rs +++ b/src/database/models.rs @@ -10,7 +10,7 @@ pub struct Mod { pub downloads: i32, pub categories: Vec, pub body_path: String, - pub icon_path: String + pub icon_path: String, } #[derive(Queryable)] @@ -20,10 +20,9 @@ pub struct Version { pub title: String, pub changelog_path: String, pub files_path: Vec, - pub date_published: NaiveDate, + pub date_published: NaiveDate, pub author: String, pub downloads: i32, pub dependencies: Vec, - pub game_versions: Vec + pub game_versions: Vec, } - diff --git a/src/helpers/contains.rs b/src/helpers/contains.rs index ded266d2..35066156 100644 --- a/src/helpers/contains.rs +++ b/src/helpers/contains.rs @@ -4,11 +4,28 @@ use handlebars::*; pub struct ContainsHelper; impl HelperDef for ContainsHelper { - fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, r: &'reg Handlebars<'_>, ctx: &'rc Context, rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult { - let array = h.param(0).map(|v| serde_json::from_value::>(v.value().clone()).unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?; - let value = h.param(1).map(|v| v.value().as_str().unwrap()).ok_or_else(|| RenderError::new("Parameter not found!"))?; + fn call<'reg: 'rc, 'rc>( + &self, + h: &Helper<'reg, 'rc>, + r: &'reg Handlebars<'_>, + ctx: &'rc Context, + rc: &mut RenderContext<'reg, 'rc>, + out: &mut dyn Output, + ) -> HelperResult { + let array = h + .param(0) + .map(|v| serde_json::from_value::>(v.value().clone()).unwrap()) + .ok_or_else(|| RenderError::new("Parameter not found!"))?; + let value = h + .param(1) + .map(|v| v.value().as_str().unwrap()) + .ok_or_else(|| RenderError::new("Parameter not found!"))?; - let tmpl = if array.contains(&String::from(value)) { h.template() } else { h.inverse() }; + let tmpl = if array.contains(&String::from(value)) { + h.template() + } else { + h.inverse() + }; match tmpl { Some(ref t) => t.render(r, ctx, rc, out), diff --git a/src/helpers/format_human.rs b/src/helpers/format_human.rs index 794dea34..db15b410 100644 --- a/src/helpers/format_human.rs +++ b/src/helpers/format_human.rs @@ -5,7 +5,14 @@ use handlebars::*; pub struct HumanFormatHelper; impl HelperDef for HumanFormatHelper { - fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Handlebars<'_>, _ctx: &'rc Context, _rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult { + fn call<'reg: 'rc, 'rc>( + &self, + h: &Helper<'reg, 'rc>, + _r: &'reg Handlebars<'_>, + _ctx: &'rc Context, + _rc: &mut RenderContext<'reg, 'rc>, + out: &mut dyn Output, + ) -> HelperResult { let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0); let mut formatted = human_format::Formatter::new().format(param); @@ -15,4 +22,4 @@ impl HelperDef for HumanFormatHelper { Ok(()) } -} \ No newline at end of file +} diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index 0c271160..bd00ba6b 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -2,4 +2,4 @@ mod contains; mod format_human; pub use contains::ContainsHelper; -pub use format_human::HumanFormatHelper; \ No newline at end of file +pub use format_human::HumanFormatHelper; diff --git a/src/main.rs b/src/main.rs index fd3972c2..d69a7039 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,14 @@ extern crate serde_json; #[macro_use] extern crate diesel; +use actix_files as fs; use actix_web::{web, App, HttpServer}; use handlebars::*; -use actix_files as fs; -mod schema; -mod routes; -mod helpers; mod database; +mod helpers; +mod routes; +mod schema; #[actix_rt::main] async fn main() -> std::io::Result<()> { @@ -39,8 +39,7 @@ async fn main() -> std::io::Result<()> { .service(routes::search_get) .service(routes::mod_editor_get) }) - .bind("127.0.0.1:8000")? - .run() - .await + .bind("127.0.0.1:8000")? + .run() + .await } - diff --git a/src/routes/index.rs b/src/routes/index.rs index 29745d95..9f981a36 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -1,4 +1,4 @@ -use actix_web::{web, HttpResponse, get}; +use actix_web::{get, web, HttpResponse}; use handlebars::*; #[get("/")] @@ -9,4 +9,4 @@ pub async fn index_get(hb: web::Data>) -> HttpResponse { let body = hb.render("index", &data).unwrap(); HttpResponse::Ok().body(body) -} \ No newline at end of file +} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 0149d5ed..f5a5fe89 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,11 +1,11 @@ -mod search; mod index; mod mod_editor; +mod search; pub use self::mod_editor::mod_editor_get; +pub use self::search::index_mods; pub use self::search::search_get; pub use self::search::search_post; -pub use self::search::index_mods; -pub use self::index::index_get; \ No newline at end of file +pub use self::index::index_get; diff --git a/src/routes/mod_editor.rs b/src/routes/mod_editor.rs index eb0546ad..f5903faf 100644 --- a/src/routes/mod_editor.rs +++ b/src/routes/mod_editor.rs @@ -1,4 +1,4 @@ -use actix_web::{web, HttpResponse, get}; +use actix_web::{get, web, HttpResponse}; use handlebars::*; #[get("modeditor")] @@ -9,4 +9,4 @@ pub async fn mod_editor_get(hb: web::Data>) -> HttpResponse { let body = hb.render("mod_editor", &data).unwrap(); HttpResponse::Ok().body(body) -} \ No newline at end of file +} diff --git a/src/schema.rs b/src/schema.rs index aa0039f2..523e9514 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -27,7 +27,4 @@ table! { } } -allow_tables_to_appear_in_same_query!( - mods, - versions, -); +allow_tables_to_appear_in_same_query!(mods, versions,);