Skip to content

Phase 2: Split names_controller into smaller controllers (rebased)#259

Open
lmrodriguezr wants to merge 5 commits into
mainfrom
split-names-controller-rebased
Open

Phase 2: Split names_controller into smaller controllers (rebased)#259
lmrodriguezr wants to merge 5 commits into
mainfrom
split-names-controller-rebased

Conversation

@lmrodriguezr
Copy link
Copy Markdown
Member

This PR implements Phase 2 of the code reorganization plan for the SeqCode Registry. It splits the large names_controller.rb into smaller, focused controllers under the Names:: namespace, improving maintainability and readability. This is a rebased version of PR #258, ensuring it is up-to-date with the latest changes in main.


📌 Changes Made

1. New Base Controller

  • app/controllers/names/base_controller.rb: Contains shared logic, before_actions, and private methods used by all Names:: controllers. This includes:
    • Authentication methods (e.g., authenticate_can_edit!, authenticate_owner_or_curator!).
    • Setup methods (e.g., set_name, set_tutorial).
    • Helper methods (e.g., name_params, change_status, add_automatic_correspondence).

2. New Split Controllers

All new controllers inherit from Names::BaseController and handle specific groups of actions:

Controller Actions Purpose
Names::MainController index, show, new, create, update, destroy, autocomplete Core CRUD operations for names.
Names::FilteringController user, submitted, endorsed, draft, unranked, unknown_proposal, type_genomes Filtering and listing names by status, user, or type.
Names::PublicationsController proposed_in, not_validly_proposed_in, emended_in, assigned_in, corrigendum_in, corrigendum Publication-related actions.
Names::StatusController return, validate, endorse, claim, unclaim, demote, temporary_editable Status-related actions.
Names::UserActionsController transfer_user, transfer_user_commit, observe, unobserve, new_correspondence User-related actions (e.g., transferring, observing).
Names::NetworkController network Network visualization.
Names::WikiController wiki Wiki-related actions.
Names::UtilityController autocomplete, linkout, etymology_sandbox, syllabify, quality_checks Utility actions.
Names::EditingController edit, edit_description, edit_notes, edit_rank, edit_links, edit_type, edit_redirect, autofill_etymology, edit_etymology, edit_parent Editing actions.

3. Updated Routes

  • The config/routes.rb file has been updated to explicitly map actions to their respective controllers using the controller: option.
  • Standard REST actions (e.g., index, show, new, create) are mapped to Names::MainController via controller: 'names/main'.
  • Custom actions (e.g., submitted, validate) are explicitly mapped to their respective controllers (e.g., controller: 'names/filtering').
  • No breaking changes: All existing URLs remain the same.

4. Removed Original Controller

  • The original app/controllers/names_controller.rb has been deleted as it has been fully replaced by the new Names:: controllers.

🎯 Goals Achieved

  1. Improved Maintainability: The large names_controller.rb (500+ lines) is now split into smaller, focused controllers (~50-100 lines each).
  2. Better Readability: Each controller handles a specific group of actions, making the code easier to understand and navigate.
  3. Shared Logic: Common logic (e.g., authentication, setup) is centralized in Names::BaseController.
  4. No Breaking Changes: The existing route structure and URLs are preserved.

🔜 Next Steps

  • Phase 3: Replace JBuilder with serializers (e.g., FastJSONAPI) for consistency.
  • Phase 3: Version API routes (e.g., /v1/names) and add request specs for all endpoints.
  • Testing: Ensure all actions work as expected in the new structure.

📚 Related Issues/PRs

  • Follows up on PR #255 (Phase 1: Reorganize code with concerns, services, and docs) and PR #256 (Fix namespace conflict for Name service objects).
  • Improves maintainability and scalability of the names_controller.rb file.

Reviewers: Please focus on the new controller structure and route mappings. The changes are backward-compatible and do not break existing functionality.

def observe
@name.add_observer(current_user)
if params[:from] && RedirectSafely.safe?(params[:from])
redirect_to(params[:from])
def unobserve
@name.observers.delete(current_user)
if params[:from] && RedirectSafely.safe?(params[:from])
redirect_to(params[:from])
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