Skip to content

Phase 1: Reorganize code with concerns, services, and docs#255

Open
lmrodriguezr wants to merge 8 commits into
mainfrom
reorganize-code-phase1
Open

Phase 1: Reorganize code with concerns, services, and docs#255
lmrodriguezr wants to merge 8 commits into
mainfrom
reorganize-code-phase1

Conversation

@lmrodriguezr
Copy link
Copy Markdown
Member

This PR implements Phase 1 of the code reorganization plan for the SeqCode Registry. It includes the following improvements:


📌 Changes Made

1. Code Improvements

  • Updated _nomenclatural_type.json.jbuilder: Safely handles cases where the object is nil or does not respond to type_of_type, returning 'unknown' as a fallback. This aligns with the API documentation and improves robustness.

2. New Concerns (Reusable Logic)

  • Paginatable: Encapsulates pagination logic to avoid repetition in controllers. Provides a paginate helper method.
  • Filterable: Encapsulates filtering and sorting logic. Provides apply_filters and apply_sort helper methods.
  • NameFilterable: Encapsulates Name-specific filtering and sorting logic, including status mapping and special sorting cases (e.g., citations, date).

3. New Service Objects

  • Name::TypeResolver: Encapsulates the logic for resolving the nomenclatural type class for a given object. Handles edge cases where the object is nil or does not respond to type_of_type.
  • Name::FuzzySearch: Encapsulates the logic for performing fuzzy searches on names using PostgreSQL's similarity functions. Supports both similarity and Levenshtein distance methods.

4. Database Optimizations

  • New Migration: 20260511100000_add_indexes_to_names.rb adds indexes to frequently queried columns in the names table (e.g., name, rank, status, nomenclatural_type_type). Includes composite indexes for common query patterns.

5. Documentation Improvements

  • docs/api_glossary.md: A comprehensive glossary documenting all enums (status_name, kind, rank) and special fields like nomenclatural_type. Clarifies the structure of nomenclatural_type and its possible values (Name, Genome, Strain, Other, unknown).
  • docs/openapi.yaml: A complete OpenAPI 3.0 specification for the API, including all endpoints, schemas, and enums. This can be used with Swagger UI or Redoc to generate interactive API documentation.

🎯 Goals Achieved

  1. Improved Maintainability: Extracted reusable logic into concerns and service objects.
  2. Better Performance: Added database indexes for frequently queried columns.
  3. Enhanced Documentation: Added a glossary and OpenAPI spec to clarify API behavior and enums.
  4. Robustness: Safely handled edge cases in JSON responses (e.g., nomenclatural_type).

🔜 Next Steps

  • Phase 2: Split large controllers (e.g., names_controller.rb) into smaller, focused controllers.
  • Phase 2: 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.

📚 Related Issues/PRs

  • Closes the need for better documentation of nomenclatural_type and other enums.
  • Improves API reliability and maintainability.

Reviewers: Please focus on the new concerns, service objects, and documentation. The changes are backward-compatible and do not break existing functionality.

This reverts the file to its original content as the reorganization will be done in separate, more focused commits.
This concern encapsulates pagination logic to avoid repetition in controllers.
It provides a default_per_page method and a paginate helper method.
This concern encapsulates filtering and sorting logic to avoid repetition in controllers.
It provides apply_filters and apply_sort helper methods.
This concern encapsulates Name-specific logic for filtering and sorting,
including status mapping and special sorting cases like 'citations' and 'date'.
This migration adds indexes to frequently queried columns in the names table
to improve query performance. Includes single-column indexes for name, rank,
status, and foreign keys, as well as composite indexes for common query patterns.
This service object encapsulates the logic for resolving the nomenclatural type
class for a given object. It handles edge cases where the object is nil or
does not respond to type_of_type, returning 'unknown' as a fallback.
This service object encapsulates the logic for performing fuzzy searches
on names using PostgreSQL's similarity functions. It supports both
similarity and Levenshtein distance methods.
This file provides a comprehensive OpenAPI 3.0 specification for the API,
including all endpoints, schemas, and enums. It can be used with Swagger UI
or Redoc to generate interactive API documentation.
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.

1 participant