Skip to content

Commit ae45068

Browse files
graylikemeclaude
andcommitted
feat: add factionType filter to units query
Allows filtering units by faction classification (GREAT_HOUSE, CLAN, PERIPHERY, etc.) via unit_availability join, so roster builders can request e.g. "all mechs available to any Great House faction" without specifying each faction individually. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e618e93 commit ae45068

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

crates/api/src/db/units.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct UnitFilter<'a> {
4949
pub bv_min: Option<i32>,
5050
pub bv_max: Option<i32>,
5151
pub faction_slug: Option<&'a str>,
52+
pub faction_type: Option<&'a str>,
5253
pub era_slug: Option<&'a str>,
5354
pub is_omnimech: Option<bool>,
5455
pub config: Option<&'a str>,
@@ -130,6 +131,14 @@ pub async fn search(
130131
builder.push_bind(faction);
131132
builder.push(")");
132133
}
134+
if let Some(ft) = filter.faction_type {
135+
builder.push(r#" AND EXISTS (
136+
SELECT 1 FROM unit_availability ua
137+
JOIN factions f2 ON f2.id = ua.faction_id
138+
WHERE ua.unit_id = u.id AND f2.faction_type = "#);
139+
builder.push_bind(ft);
140+
builder.push(")");
141+
}
133142
if let Some(era) = filter.era_slug {
134143
builder.push(r#" AND EXISTS (
135144
SELECT 1 FROM unit_availability ua
@@ -364,6 +373,7 @@ mod tests {
364373
bv_min: None,
365374
bv_max: None,
366375
faction_slug: None,
376+
faction_type: None,
367377
era_slug: None,
368378
is_omnimech: None,
369379
config: None,

crates/api/src/graphql/query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl QueryRoot {
148148
#[graphql(desc = "Minimum Battle Value filter (inclusive).")] bv_min: Option<i32>,
149149
#[graphql(desc = "Maximum Battle Value filter (inclusive).")] bv_max: Option<i32>,
150150
#[graphql(desc = "Filter to units available to this faction. Lowercase, hyphen-separated slug (e.g. \"clan-wolf\").")] faction_slug: Option<String>,
151+
#[graphql(desc = "Filter to units available to any faction of this type.")] faction_type: Option<FactionTypeFilter>,
151152
#[graphql(desc = "Filter to units available in this era.")] era_slug: Option<EraFilter>,
152153
#[graphql(desc = "Filter to OmniMechs only (true) or non-OmniMechs (false).")] is_omnimech: Option<bool>,
153154
#[graphql(desc = "Filter by chassis config. One of: Biped, Quad, Tripod, LAM.")] config: Option<String>,
@@ -169,6 +170,7 @@ impl QueryRoot {
169170
bv_min,
170171
bv_max,
171172
faction_slug: faction_slug.as_deref(),
173+
faction_type: faction_type.map(|f| f.as_db_str()),
172174
era_slug: era_slug.map(|e| e.as_db_str()),
173175
is_omnimech,
174176
config: config.as_deref(),

0 commit comments

Comments
 (0)