mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Manually filter mouser search results to fix the edgecase, that the API returned multiple results for an exact part number
This fixes issue #888 and issue #616
This commit is contained in:
parent
49ee9131d0
commit
7275db27e7
1 changed files with 8 additions and 2 deletions
|
@ -94,6 +94,7 @@ class MouserProvider implements InfoProviderInterface
|
||||||
From the startingRecord, the number of records specified will be returned up to the end of the recordset.
|
From the startingRecord, the number of records specified will be returned up to the end of the recordset.
|
||||||
This is useful for paging through the complete recordset of parts matching keyword.
|
This is useful for paging through the complete recordset of parts matching keyword.
|
||||||
|
|
||||||
|
|
||||||
searchOptions string
|
searchOptions string
|
||||||
Optional.
|
Optional.
|
||||||
If not provided, the default is None.
|
If not provided, the default is None.
|
||||||
|
@ -176,11 +177,16 @@ class MouserProvider implements InfoProviderInterface
|
||||||
throw new \RuntimeException('No part found with ID '.$id);
|
throw new \RuntimeException('No part found with ID '.$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Manually filter out the part with the correct ID
|
||||||
|
$tmp = array_filter($tmp, fn(PartDetailDTO $part) => $part->provider_id === $id);
|
||||||
|
if (count($tmp) === 0) {
|
||||||
|
throw new \RuntimeException('No part found with ID '.$id);
|
||||||
|
}
|
||||||
if (count($tmp) > 1) {
|
if (count($tmp) > 1) {
|
||||||
throw new \RuntimeException('Multiple parts found with ID '.$id . ' ('.count($tmp).' found). This is basically a bug in Mousers API response. See issue #616.');
|
throw new \RuntimeException('Multiple parts found with ID '.$id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tmp[0];
|
return reset($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCapabilities(): array
|
public function getCapabilities(): array
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue