Added basic possibilty to create parts based on infoProviders

This commit is contained in:
Jan Böhmer 2023-07-09 23:31:40 +02:00
parent 538476be99
commit 716a56979d
12 changed files with 476 additions and 25 deletions

View file

@ -23,12 +23,14 @@ declare(strict_types=1);
namespace App\Services\InfoProviderSystem;
use App\Entity\Parts\Part;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
class PartInfoRetriever
{
public function __construct(private readonly ProviderRegistry $provider_registry)
public function __construct(private readonly ProviderRegistry $provider_registry, private readonly DTOtoEntityConverter $dto_to_entity_converter)
{
}
@ -57,4 +59,27 @@ class PartInfoRetriever
return $results;
}
/**
* Retrieves the details for a part from the given provider with the given (provider) part id
* @param string $provider_key
* @param string $part_id
* @return
*/
public function getDetails(string $provider_key, string $part_id): PartDetailDTO
{
return $this->provider_registry->getProviderByKey($provider_key)->getDetails($part_id);
}
public function getDetailsForSearchResult(SearchResultDTO $search_result): PartDetailDTO
{
return $this->getDetails($search_result->provider_key, $search_result->provider_id);
}
public function createPart(string $provider_key, string $part_id): Part
{
$details = $this->getDetails($provider_key, $part_id);
return $this->dto_to_entity_converter->convertPart($details);
}
}