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

@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.

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