[WIP] use URL params

master
Tait Hoyem 1 year ago
parent ab1e73dca7
commit 5b964c9650

@ -33,6 +33,7 @@ i18n-embed-fl = "0.6.6"
rust-embed = { version = "6.6.1", features = ["axum"] } rust-embed = { version = "6.6.1", features = ["axum"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
ibihf-macros = { version = "0.1.0", path = "ibihf-macros" } ibihf-macros = { version = "0.1.0", path = "ibihf-macros" }
phf = { version = "0.11.1", features = ["macros"] }
[dev-dependencies] [dev-dependencies]
tokio-test = "0.4.2" tokio-test = "0.4.2"

@ -57,7 +57,7 @@ struct TableNameOpts {
fn get_map_filter(field: &Field) -> Option<String> { fn get_map_filter(field: &Field) -> Option<String> {
let name = &field.ident.as_ref().unwrap(); 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()) Some(name.to_string())
} else { } else {
None None
@ -86,7 +86,6 @@ pub fn derive_get(input: TokenStream) -> TokenStream {
Data::Struct(ref data) => &data.fields, Data::Struct(ref data) => &data.fields,
_ => panic!("MyDerive only supports structs"), _ => panic!("MyDerive only supports structs"),
}; };
let by_many_names: Vec<String> = fields.iter().filter_map(get_many_map_filter).collect(); let by_many_names: Vec<String> = fields.iter().filter_map(get_many_map_filter).collect();
let by_many_funcs: Vec<TokenStream2> = by_many_names.iter() let by_many_funcs: Vec<TokenStream2> = by_many_names.iter()
.map(|name| { .map(|name| {

@ -34,12 +34,15 @@ pub fn goal_assist_name(goal: &GoalDetails, lang: &SupportedLanguage) -> ::askam
}; };
Ok(format!("{f_names} {l_name}")) Ok(format!("{f_names} {l_name}"))
} }
pub fn shot_assist_name(goal: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result<String> { pub fn shot_assist_name(shot: &ShotDetails, lang: &SupportedLanguage) -> ::askama::Result<String> {
let Some(ref f_names) = goal.second_assist_first_names else { if !shot.is_goal {
return Ok(lang.lookup("not-applicable")); 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 { let Some(ref l_name) = shot.first_assist_last_name else {
return Ok(lang.lookup("not-applicable")); return Ok(lang.lookup("unassisted"));
}; };
Ok(format!("{f_names} {l_name}")) Ok(format!("{f_names} {l_name}"))
} }
@ -56,16 +59,20 @@ pub fn goal_second_assist_name(
Ok(format!("{f_names} {l_name}")) Ok(format!("{f_names} {l_name}"))
} }
pub fn shot_second_assist_name( pub fn shot_second_assist_name(
goal: &ShotDetails, shot: &ShotDetails,
lang: &SupportedLanguage, lang: &SupportedLanguage,
) -> ::askama::Result<String> { ) -> ::askama::Result<String> {
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")); 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 { let Some(ref l_name) = shot.second_assist_last_name else {
return Ok(lang.lookup("not-applicable")); 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<String> { pub fn shot_player_name(shot: &ShotDetails) -> ::askama::Result<String> {
Ok(format!( Ok(format!(

@ -73,6 +73,7 @@ macro_rules! impl_url_gen {
} }
} }
use static_assertions::assert_impl_all; use static_assertions::assert_impl_all;
use traits::TemplateUrl; use traits::TemplateUrl;
#[macro_use] #[macro_use]
@ -134,6 +135,14 @@ struct TeamGameStatsTemplate<'a> {
teams: Vec<TeamStats>, teams: Vec<TeamStats>,
} }
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)] #[derive(Template, TemplateUrl)]
#[urls(url_key = "league_url", url_key_template = "league_url_tmpl")] #[urls(url_key = "league_url", url_key_template = "league_url_tmpl")]
#[template(path = "division_list.html")] #[template(path = "division_list.html")]

@ -32,8 +32,7 @@ pub struct League {
pub id: i32, pub id: i32,
pub name: Option<String>, pub name: Option<String>,
} }
//impl_localized_get!(League, league_name);
//impl_localized_all!(League);
/* /*
#[derive(FromRow, Serialize, Deserialize, Debug, ormx::Patch)] #[derive(FromRow, Serialize, Deserialize, Debug, ormx::Patch)]
#[ormx(table_name = "leagues", table = League, id = "id")] #[ormx(table_name = "leagues", table = League, id = "id")]
@ -56,9 +55,6 @@ pub struct Division {
pub league: i32, pub league: i32,
pub name: Option<String>, pub name: Option<String>,
} }
//impl_localized_get!(Division, division_name);
//impl_localized_get_by_many!(Division, league);
//impl_localized_all!(Division);
#[derive(FromRow, Serialize, Deserialize, Debug)] #[derive(FromRow, Serialize, Deserialize, Debug)]
//#[ormx(table_name = "divisions", table = Division, id = "id")] //#[ormx(table_name = "divisions", table = Division, id = "id")]
@ -172,8 +168,6 @@ pub struct Game {
pub start_at: DateTime<Utc>, pub start_at: DateTime<Utc>,
pub end_at: DateTime<Utc>, pub end_at: DateTime<Utc>,
} }
//impl_localized_get!(Game, game_name);
//impl_localized_get_by_many!(Game, division);
#[derive(FromRow, Deserialize, Serialize, Debug, ormx::Table)] #[derive(FromRow, Deserialize, Serialize, Debug, ormx::Table)]
#[ormx(table = "periods", id = id, insertable, deletable)] #[ormx(table = "periods", id = id, insertable, deletable)]

Loading…
Cancel
Save