Skip to content

Feature Implementation Plan: Add Missing Fields to CoffeeBeanDTO

📋 Todo Checklist

  • [ ] Add suitableForEspresso and suitableForFilter properties to the CoffeeBeanDTO.
  • [ ] Update the EntityToDtoMapper service to map these new properties from the entity to the DTO.
  • [ ] Update integration tests to assert that these fields are now present in the API response for coffee bean lists.
  • [ ] Final Review and Testing

🔍 Analysis & Investigation

Codebase Structure

  • DTO: The file src/DTO/Api/CoffeeBeanDTO.php is the primary target for changes.
  • Mapper: The service src/Service/Api/Mapper/EntityToDtoMapper.php will be updated to populate the new DTO fields.

Root Cause Analysis

The issue is a simple omission. When the CoffeeBeanDTO was created to solve the caching serialization problem, the suitableForEspresso and suitableForFilter fields were overlooked and not included in the DTO's properties. The API's list endpoints use this DTO to generate their response, so the fields are missing from the final JSON output, even though they are present on the source CoffeeBean entity and are filterable.

Dependencies & Integration Points

  • This change is self-contained and has no external dependencies. It directly affects the data contract of the /api/coffee-beans list endpoint.

Considerations & Challenges

  • This is a low-risk, high-value change. The only challenge is ensuring the mapping logic in the EntityToDtoMapper is correctly implemented.

📝 Implementation Plan

Prerequisites

  • No new external dependencies are required.

Step-by-Step Implementation

  1. Update the CoffeeBeanDTO

    • Files to modify: src/DTO/Api/CoffeeBeanDTO.php
    • Changes needed: Add the two new boolean properties to the __construct method.
      // In CoffeeBeanDTO.php's constructor
      // ... after status
      public ?string $status = null,
      public bool $suitableForEspresso = true,
      public bool $suitableForFilter = true,
      public ?\DateTimeInterface $createdAt = null,
      // ...
      
  2. Update the EntityToDtoMapper

    • Files to modify: src/Service/Api/Mapper/EntityToDtoMapper.php
    • Changes needed: In the mapCoffeeBeansToDtos method (or equivalent), add the mapping for the new fields when constructing the CoffeeBeanDTO.
      // In the DTO constructor call inside the mapper
      // ...
      status: $bean->getStatus()?->value,
      suitableForEspresso: $bean->isSuitableForEspresso(),
      suitableForFilter: $bean->isSuitableForFilter(),
      createdAt: $bean->getCreatedAt(),
      // ...
      

Testing Strategy

  • Integration Tests:
    • Modify the existing integration test for the /api/coffee-beans list endpoint.
    • Fetch the list of coffee beans.
    • Take the first item from the items array.
    • Assert that the response now contains the keys suitableForEspresso and suitableForFilter.
    • Assert that their values are booleans.

🎯 Success Criteria

  • A GET request to the /api/coffee-beans list endpoint now includes the suitableForEspresso and suitableForFilter boolean fields in each coffee bean object.
  • The API response is now consistent with the API's filtering capabilities.
  • The change is fully covered by integration tests.