From 5b964c96502b87404d600a10e2a5573406c84ae4 Mon Sep 17 00:00:00 2001 From: Tait Hoyem Date: Fri, 28 Apr 2023 15:58:40 -0600 Subject: [PATCH] [WIP] use URL params --- Cargo.toml | 1 + ibihf-macros/src/lib.rs | 3 +-- src/filters.rs | 25 ++++++++++++++++--------- src/main.rs | 9 +++++++++ src/model.rs | 8 +------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 850b49c..c9ee614 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ i18n-embed-fl = "0.6.6" rust-embed = { version = "6.6.1", features = ["axum"] } lazy_static = "1.4.0" ibihf-macros = { version = "0.1.0", path = "ibihf-macros" } +phf = { version = "0.11.1", features = ["macros"] } [dev-dependencies] tokio-test = "0.4.2" diff --git a/ibihf-macros/src/lib.rs b/ibihf-macros/src/lib.rs index 8bca315..d759261 100644 --- a/ibihf-macros/src/lib.rs +++ b/ibihf-macros/src/lib.rs @@ -57,7 +57,7 @@ struct TableNameOpts { fn get_map_filter(field: &Field) -> Option { let name = &field.ident.as_ref().unwrap(); - if field.attrs.iter().any(|attr| attr.path.is_ident("get")) { + if field.attrs.iter().any(|attr| attr.path.is_ident("id")) { Some(name.to_string()) } else { None @@ -86,7 +86,6 @@ pub fn derive_get(input: TokenStream) -> TokenStream { Data::Struct(ref data) => &data.fields, _ => panic!("MyDerive only supports structs"), }; - let by_many_names: Vec = fields.iter().filter_map(get_many_map_filter).collect(); let by_many_funcs: Vec = by_many_names.iter() .map(|name| { diff --git a/src/filters.rs b/src/filters.rs index 87f8e58..a8f361c 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -34,12 +34,15 @@ pub fn goal_assist_name(goal: &GoalDetails, lang: &SupportedLanguage) -> ::askam }; Ok(format!("{f_names} {l_name}")) } -pub fn shot_assist_name(goal: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result { - let Some(ref f_names) = goal.second_assist_first_names else { +pub fn shot_assist_name(shot: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result { + if !shot.is_goal { return Ok(lang.lookup("not-applicable")); + } + let Some(ref f_names) = shot.first_assist_first_names else { + return Ok(lang.lookup("unassisted")); }; - let Some(ref l_name) = goal.second_assist_last_name else { - return Ok(lang.lookup("not-applicable")); + let Some(ref l_name) = shot.first_assist_last_name else { + return Ok(lang.lookup("unassisted")); }; Ok(format!("{f_names} {l_name}")) } @@ -56,16 +59,20 @@ pub fn goal_second_assist_name( Ok(format!("{f_names} {l_name}")) } pub fn shot_second_assist_name( - goal: &ShotDetails, + shot: &ShotDetails, lang: &SupportedLanguage, ) -> ::askama::Result { - let Some(ref f_names) = goal.second_assist_first_names else { + if !shot.is_goal || + shot.second_assist_id.is_none() { return Ok(lang.lookup("not-applicable")); + } + let Some(ref f_names) = shot.second_assist_first_names else { + return Ok(lang.lookup("unassisted")); }; - let Some(ref l_name) = goal.second_assist_last_name else { - return Ok(lang.lookup("not-applicable")); + let Some(ref l_name) = shot.second_assist_last_name else { + return Ok(lang.lookup("unassisted")); }; - Ok(format!("{f_names} {l_name}")) + Ok(format!("{f_names} {l_name}")) } pub fn shot_player_name(shot: &ShotDetails) -> ::askama::Result { Ok(format!( diff --git a/src/main.rs b/src/main.rs index 3063675..b527825 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,7 @@ macro_rules! impl_url_gen { } } + use static_assertions::assert_impl_all; use traits::TemplateUrl; #[macro_use] @@ -134,6 +135,14 @@ struct TeamGameStatsTemplate<'a> { teams: Vec, } +trait Link { + type Params; + const LINK_URL_KEY: &'static str; + const LINK_TEMPLATE_KEY: &'static str; + fn lang_link(p: Params) -> LangLink; + +} + #[derive(Template, TemplateUrl)] #[urls(url_key = "league_url", url_key_template = "league_url_tmpl")] #[template(path = "division_list.html")] diff --git a/src/model.rs b/src/model.rs index 3621d49..7aef01f 100644 --- a/src/model.rs +++ b/src/model.rs @@ -32,8 +32,7 @@ pub struct League { pub id: i32, pub name: Option, } -//impl_localized_get!(League, league_name); -//impl_localized_all!(League); + /* #[derive(FromRow, Serialize, Deserialize, Debug, ormx::Patch)] #[ormx(table_name = "leagues", table = League, id = "id")] @@ -56,9 +55,6 @@ pub struct Division { pub league: i32, pub name: Option, } -//impl_localized_get!(Division, division_name); -//impl_localized_get_by_many!(Division, league); -//impl_localized_all!(Division); #[derive(FromRow, Serialize, Deserialize, Debug)] //#[ormx(table_name = "divisions", table = Division, id = "id")] @@ -172,8 +168,6 @@ pub struct Game { pub start_at: DateTime, pub end_at: DateTime, } -//impl_localized_get!(Game, game_name); -//impl_localized_get_by_many!(Game, division); #[derive(FromRow, Deserialize, Serialize, Debug, ormx::Table)] #[ormx(table = "periods", id = id, insertable, deletable)]