refactor: extract dashboard event queries into DashboardQuery object#2708
Merged
Conversation
cd2ea1a to
2e40173
Compare
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).
2e40173 to
13cddd2
Compare
KimberleyCook
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extract the event-building query logic from
DashboardControllerinto a dedicatedDashboardQueryquery object underapp/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
app/queries/dashboard_query.rbwith 3 public class methods (upcoming_events,upcoming_events_for_user(member),total_upcoming_events_count) and a private helperall_eventsMAX_WORKSHOP_QUERYandDEFAULT_UPCOMING_EVENTSto the query objectDashboardQuery.*callsyear_paramandtop_coach_queryin the controller (param extraction and a simple scope chain)spec/queries/dashboard_query_spec.rbwith unit tests for all 3 public methods (9 examples)Testing
spec/queries/dashboard_query_spec.rb— 9 examples, 0 failuresspec/views/dashboard/show.html.haml_spec.rb— 1 example, 0 failures