Renamed dto to make their relation to batch searches more clear

This commit is contained in:
Jan Böhmer 2025-09-21 17:49:00 +02:00
parent 16126c4000
commit 92cd645945
9 changed files with 53 additions and 54 deletions

View file

@ -24,9 +24,8 @@ namespace App\Services\InfoProviderSystem\DTOs;
/**
* Represents a mapping between a part field and the info providers that should search in that field.
* This DTO provides type safety and better structure than raw arrays for field mapping configuration.
*/
readonly class FieldMappingDTO
readonly class BulkSearchFieldMappingDTO
{
/**
* @param string $field The field to search in (e.g., 'mpn', 'name', or supplier-specific fields like 'digikey_spn')

View file

@ -25,9 +25,9 @@ namespace App\Services\InfoProviderSystem\DTOs;
use App\Entity\Parts\Part;
/**
* Represents a search result from bulk search with additional context information, like how the part was found.
* Represents a single search result from bulk search with additional context information, like how the part was found.
*/
readonly class BulkSearchResultDTO
readonly class BulkSearchPartResultDTO
{
public function __construct(
/** The base search result DTO containing provider data */

View file

@ -26,13 +26,13 @@ use App\Entity\Parts\Part;
/**
* Represents the search results for a single part from bulk info provider search.
* This DTO provides type safety and clear structure for part search results.
* It contains multiple search results, that match the part.
*/
readonly class PartSearchResultsDTO
readonly class BulkSearchPartResultsDTO
{
/**
* @param Part $part The part that was searched for
* @param BulkSearchResultDTO[] $searchResults Array of search results found for this part
* @param BulkSearchPartResultDTO[] $searchResults Array of search results found for this part
* @param string[] $errors Array of error messages encountered during search
*/
public function __construct(
@ -72,12 +72,12 @@ readonly class PartSearchResultsDTO
/**
* Get search results sorted by priority (ascending).
* @return BulkSearchResultDTO[]
* @return BulkSearchPartResultDTO[]
*/
public function getResultsSortedByPriority(): array
{
$results = $this->searchResults;
usort($results, static fn(BulkSearchResultDTO $a, BulkSearchResultDTO $b) => $a->priority <=> $b->priority);
usort($results, static fn(BulkSearchPartResultDTO $a, BulkSearchPartResultDTO $b) => $a->priority <=> $b->priority);
return $results;
}
}

View file

@ -32,7 +32,7 @@ use Doctrine\ORM\EntityManagerInterface;
readonly class BulkSearchResponseDTO implements \ArrayAccess
{
/**
* @param PartSearchResultsDTO[] $partResults Array of search results for each part
* @param BulkSearchPartResultsDTO[] $partResults Array of search results for each part
*/
public function __construct(
public array $partResults
@ -41,10 +41,10 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess
/**
* Replaces the search results for a specific part, and returns a new instance.
* @param Part|int $part
* @param PartSearchResultsDTO $new_results
* @param BulkSearchPartResultsDTO $new_results
* @return BulkSearchResponseDTO
*/
public function replaceResultsForPart(Part|int $part, PartSearchResultsDTO $new_results): self
public function replaceResultsForPart(Part|int $part, BulkSearchPartResultsDTO $new_results): self
{
$array = $this->partResults;
foreach ($array as $index => $partResult) {
@ -85,7 +85,7 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess
/**
* Get all parts that have search results.
* @return PartSearchResultsDTO[]
* @return BulkSearchPartResultsDTO[]
*/
public function getPartsWithResults(): array
{
@ -94,7 +94,7 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess
/**
* Get all parts that have errors.
* @return PartSearchResultsDTO[]
* @return BulkSearchPartResultsDTO[]
*/
public function getPartsWithErrors(): array
{
@ -175,9 +175,9 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess
{
$partResults = [];
foreach ($data as $partData) {
$partResults[] = new PartSearchResultsDTO(
$partResults[] = new BulkSearchPartResultsDTO(
part: $entityManager->getReference(Part::class, $partData['part_id']),
searchResults: array_map(fn($result) => new BulkSearchResultDTO(
searchResults: array_map(fn($result) => new BulkSearchPartResultDTO(
searchResult: SearchResultDTO::fromNormalizedSearchResultArray($result['dto']),
sourceField: $result['source_field'] ?? null,
sourceKeyword: $result['source_keyword'] ?? null,
@ -199,7 +199,7 @@ readonly class BulkSearchResponseDTO implements \ArrayAccess
return isset($this->partResults[$offset]);
}
public function offsetGet(mixed $offset): ?PartSearchResultsDTO
public function offsetGet(mixed $offset): ?BulkSearchPartResultsDTO
{
if (!is_int($offset)) {
throw new \InvalidArgumentException("Offset must be an integer.");