Skip to content

Unify filter enums with generic Filterable trait #217

@jhodapp

Description

@jhodapp

Summary

We have duplicate filter enum definitions across the entity_api and web layers. Each filter is defined twice with manual mapping in controllers. This should be unified using a trait-based pattern.

Current State

Three filter types are duplicated:

Filter entity_api web/params Controller Mapping
RoleFilter coaching_relationship.rs coaching_relationship.rs:8 ✅ Fixed via RoleFilterable trait
Scope action.rs:239 action.rs:14 Manual match in action_controller.rs:64-67
AssigneeFilter action.rs:227 action.rs:27 Manual match in action_controller.rs:70-74

Proposed Solution

Create a generic Filterable trait in entity_api/src/filter.rs:

// entity_api/src/filter.rs
pub trait Filterable {
    // Design TBD - could be:
    // fn to_condition(&self) -> Condition;
    // or a simpler boolean predicate pattern
}

Benefits

  • Single source of truth for each filter (web layer only)
  • No manual mapping in controllers
  • Clear pattern for future filters
  • Preserved dependency graph: web → domain → entity_api

Implementation Steps

  1. Create entity_api/src/filter.rs with generic Filterable trait
  2. Refactor RoleFilterable to use the new pattern (or keep as-is if different)
  3. Create traits for Scope and AssigneeFilter
  4. Remove duplicate enums from entity_api/src/action.rs
  5. Update FindByUserParams to accept impl Trait instead of concrete types
  6. Simplify action_controller.rs to pass web types directly
  7. Update domain re-exports

Context

This was identified during PR #215 code review. The RoleFilter was fixed as a proof of concept, demonstrating the pattern works. The remaining filters should follow the same approach.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproves existing functionality or featurerefactorRefactors part of the code

    Type

    Projects

    Status

    🔖 Ready

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions