Skip to content

Phase 2: Split names_controller into smaller controllers#258

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

Phase 2: Split names_controller into smaller controllers#258
lmrodriguezr wants to merge 14 commits into
mainfrom
split-names-controller

Conversation

@lmrodriguezr
Copy link
Copy Markdown
Member

@lmrodriguezr lmrodriguezr commented May 14, 2026

This PR implements Phase 2 of the code reorganization plan for the SeqCode Registry. It focuses on improving the maintainability and modularity of the names_controller.rb by extracting shared logic into concerns and encapsulating business logic in service objects. This approach ensures no breaking changes to URLs or route helpers.


📌 Changes Made

1. Extracted Concerns

  • app/controllers/concerns/paginatable.rb: Handles pagination logic (e.g., paginate method).
  • app/controllers/concerns/filterable.rb: Provides filtering and sorting utilities (e.g., apply_filters, apply_sort).
  • app/controllers/concerns/name_filterable.rb: Encapsulates Name-specific filtering and sorting (e.g., apply_name_filters, apply_name_sort, map_status_to_value).

2. Added Service Objects

  • app/services/name/fuzzy_search.rb: Encapsulates fuzzy search logic for names using PostgreSQL's similarity functions.
  • app/services/name/type_resolver.rb: Resolves nomenclatural type classes for objects.

3. Updated names_controller.rb

  • Included concerns (Paginatable, Filterable, NameFilterable) to reuse shared logic.
  • Updated actions to use the concerns and service objects:
    • autocomplete: Now uses Services::Name::FuzzySearch.call.
    • index: Uses apply_name_filters and apply_name_sort from NameFilterable.
    • unranked and unknown_proposal: Use the paginate method from Paginatable.
  • No changes to URLs or route helpers (backward-compatible).

4. Updated _nomenclatural_type.json.jbuilder

  • Now uses Services::Name::TypeResolver.resolve(object) to determine the nomenclatural type class.

🎯 Goals Achieved

  1. Improved Maintainability: The names_controller.rb file is now more modular, with shared logic extracted into concerns and business logic encapsulated in service objects.
  2. Better Readability: Each concern and service object has a single responsibility, making the code easier to understand and navigate.
  3. No Breaking Changes: All existing URLs, route helpers, and functionality remain unchanged.
  4. Rails Idiomatic: Uses include for concerns and service objects for business logic, following Rails best practices.

🔜 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: Verify all actions work as expected with the new structure.

📚 Related Issues/PRs

  • Follows up on PR #255 (Phase 1: Reorganize code with concerns, services, and docs).
  • Improves maintainability and scalability of the names_controller.rb file.

Reviewers: Please focus on the use of concerns and service objects in names_controller.rb. The changes are backward-compatible and do not break existing functionality.

This controller contains shared logic, before_actions, and private methods
used by all Names-related controllers. It centralizes authentication, setup,
and helper methods to avoid repetition.
This controller handles the core CRUD operations for Names:
- index, show, new, create, update, destroy
- autocomplete

It inherits from Names::BaseController to reuse shared logic.
This controller handles filtering and listing names by status, user, or type:
- user, observing, submitted, endorsed, draft, unranked, unknown_proposal, type_genomes

It inherits from Names::BaseController and reuses the index logic.
This controller handles actions related to publication associations:
- proposed_in, not_validly_proposed_in, emended_in, assigned_in, corrigendum_in, corrigendum

It inherits from Names::BaseController.
This controller handles actions related to changing the status of a name:
- return, validate, endorse, claim, unclaim, demote, temporary_editable

It inherits from Names::BaseController.
This controller handles actions related to user interactions:
- transfer_user, transfer_user_commit, observe, unobserve, new_correspondence

It inherits from Names::BaseController.
This controller handles the network visualization action:
- network

It inherits from Names::BaseController.
This controller handles the wiki action:
- wiki

It inherits from Names::BaseController.
This controller handles utility actions:
- autocomplete, linkout, etymology_sandbox, syllabify, quality_checks

It inherits from Names::BaseController.
This controller handles actions related to editing name attributes:
- edit, edit_description, edit_notes, edit_rank, edit_links, edit_type,
  edit_redirect, autofill_etymology, edit_etymology, edit_parent

It inherits from Names::BaseController.
This change updates the routes to use the new Names:: namespace for controllers.
- Standard REST actions (index, show, new, create, update, destroy) are mapped to Names::MainController.
- Custom actions are explicitly mapped to their respective controllers (e.g., filtering, publications, status).
- The existing route structure and URLs remain unchanged.
Comment thread app/controllers/names/user_actions_controller.rb Fixed
Comment thread app/controllers/names/user_actions_controller.rb Fixed
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