Skip to content

refactor: extract dashboard event queries into DashboardQuery object#2708

Merged
mroderick merged 2 commits into
masterfrom
extract/dashboard-query
Jul 15, 2026
Merged

refactor: extract dashboard event queries into DashboardQuery object#2708
mroderick merged 2 commits into
masterfrom
extract/dashboard-query

Conversation

@mroderick

@mroderick mroderick commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

What

Extract the event-building query logic from DashboardController into a dedicated DashboardQuery query object under app/queries/.

Why

The controller contained domain-layer logic: cross-model event assembly (Workshop, Event, Meeting), date-based sorting and grouping, and count computation. Per layered architecture, controllers should handle HTTP concerns and delegate domain queries to lower layers.

Changes

  • Create app/queries/dashboard_query.rb with 3 public class methods (upcoming_events, upcoming_events_for_user(member), total_upcoming_events_count) and a private helper all_events
  • Move constants MAX_WORKSHOP_QUERY and DEFAULT_UPCOMING_EVENTS to the query object
  • Controller now delegates to DashboardQuery.* calls
  • Keep year_param and top_coach_query in the controller (param extraction and a simple scope chain)
  • Add spec/queries/dashboard_query_spec.rb with unit tests for all 3 public methods (9 examples)

Testing

  • spec/queries/dashboard_query_spec.rb — 9 examples, 0 failures
  • spec/views/dashboard/show.html.haml_spec.rb — 1 example, 0 failures

@mroderick mroderick force-pushed the extract/dashboard-query branch 3 times, most recently from cd2ea1a to 2e40173 Compare July 15, 2026 06:16
Move upcoming_events, upcoming_events_for_user, all_events, and
total_upcoming_events_count from DashboardController into
app/queries/dashboard_query.rb as class methods. These methods assemble
cross-model event listings (Workshop, Event, Meeting) with sorting and
limiting logic — domain concerns, not controller responsibilities.

The controller now delegates to DashboardQuery, keeping only param
extraction (year_param) and a simple scope chain (top_coach_query).
@mroderick mroderick force-pushed the extract/dashboard-query branch from 2e40173 to 13cddd2 Compare July 15, 2026 06:19
@mroderick mroderick marked this pull request as ready for review July 15, 2026 16:04
@mroderick mroderick merged commit f9ae484 into master Jul 15, 2026
9 checks passed
@mroderick mroderick deleted the extract/dashboard-query branch July 15, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants