Skip to content

Refactor: Extract shared helper for DocumentCreated event publishing in ResourceIndexItemProcessor #98

@coderabbitai

Description

@coderabbitai

Context

This issue tracks a refactoring opportunity identified during PR #97 review.

File: src/SportsData.Provider/Application/Processors/ResourceIndexItemProcessor.cs

Problem

The logic for building and publishing DocumentCreated events is duplicated across three methods:

  • PublishDocumentCreatedAsync (lines 311-346)
  • HandleNewDocumentAsync (lines 227-255)
  • HandleUpdatedDocumentAsync (lines 279-308)

Each method repeats:

  • baseUrl + providerRef construction
  • GetIncludableJson call
  • DocumentCreated instantiation with identical parameters
  • _publisher.Publish invocation
  • Follow-up log message

This duplication creates a maintenance burden—any change to the event construction (e.g., adding a field) must be applied in three places.

Proposed Solution

Extract a single shared helper method that:

  1. Takes the JSON source string and a log suffix as parameters
  2. Centralizes the baseUrl/providerRef construction
  3. Handles the DocumentCreated event instantiation
  4. Publishes the event
  5. Logs the completion

Then update the three existing methods to call this shared helper.

References

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions