mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-29 06:18:26 +02:00
Moved octopart / nexar integration configuration to the new settings system
This commit is contained in:
parent
1dbcff66d1
commit
c0c847c5be
7 changed files with 116 additions and 40 deletions
|
@ -30,6 +30,7 @@ use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
|||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||
use App\Services\OAuth\OAuthTokenManager;
|
||||
use App\Settings\InfoProviderSystem\OctopartSettings;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\HttpClient\HttpOptions;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
@ -114,9 +115,8 @@ class OctopartProvider implements InfoProviderInterface
|
|||
|
||||
public function __construct(private readonly HttpClientInterface $httpClient,
|
||||
private readonly OAuthTokenManager $authTokenManager, private readonly CacheItemPoolInterface $partInfoCache,
|
||||
private readonly string $clientId, private readonly string $secret,
|
||||
private readonly string $currency, private readonly string $country,
|
||||
private readonly int $search_limit, private readonly bool $onlyAuthorizedSellers)
|
||||
private readonly OctopartSettings $settings,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ class OctopartProvider implements InfoProviderInterface
|
|||
{
|
||||
//The client ID has to be set and a token has to be available (user clicked connect)
|
||||
//return /*!empty($this->clientId) && */ $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||
return $this->clientId !== '' && $this->secret !== '';
|
||||
return $this->settings->clientId !== '' && $this->settings->secret !== '';
|
||||
}
|
||||
|
||||
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
|
||||
|
@ -347,10 +347,10 @@ class OctopartProvider implements InfoProviderInterface
|
|||
|
||||
$result = $this->makeGraphQLCall($graphQL, [
|
||||
'keyword' => $keyword,
|
||||
'limit' => $this->search_limit,
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'authorizedOnly' => $this->onlyAuthorizedSellers,
|
||||
'limit' => $this->settings->searchLimit,
|
||||
'currency' => $this->settings->currency,
|
||||
'country' => $this->settings->country,
|
||||
'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
|
||||
]);
|
||||
|
||||
$tmp = [];
|
||||
|
@ -383,9 +383,9 @@ class OctopartProvider implements InfoProviderInterface
|
|||
|
||||
$result = $this->makeGraphQLCall($graphql, [
|
||||
'ids' => [$id],
|
||||
'currency' => $this->currency,
|
||||
'country' => $this->country,
|
||||
'authorizedOnly' => $this->onlyAuthorizedSellers,
|
||||
'currency' => $this->settings->currency,
|
||||
'country' => $this->settings->country,
|
||||
'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
|
||||
]);
|
||||
|
||||
$tmp = $this->partResultToDTO($result['data']['supParts'][0]);
|
||||
|
|
|
@ -44,6 +44,9 @@ class InfoProviderSettings
|
|||
#[EmbeddedSettings]
|
||||
public ?Element14Settings $element14 = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?OctopartSettings $octopartSettings = null;
|
||||
|
||||
#[EmbeddedSettings]
|
||||
public ?LCSCSettings $lcsc = null;
|
||||
|
||||
|
|
70
src/Settings/InfoProviderSystem/OctopartSettings.php
Normal file
70
src/Settings/InfoProviderSystem/OctopartSettings.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Settings\InfoProviderSystem;
|
||||
|
||||
use App\Settings\SettingsIcon;
|
||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CountryType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[Settings(label: new TM("settings.ips.octopart"))]
|
||||
#[SettingsIcon("fa-plug")]
|
||||
class OctopartSettings
|
||||
{
|
||||
use SettingsTrait;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.ips.digikey.client_id"),
|
||||
envVar: "PROVIDER_OCTOPART_CLIENT_ID"
|
||||
)]
|
||||
public ?string $clientId = null;
|
||||
|
||||
#[SettingsParameter(
|
||||
label: new TM("settings.ips.digikey.secret"),
|
||||
envVar: "PROVIDER_OCTOPART_SECRET"
|
||||
)]
|
||||
public ?string $secret = null;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR", "USD", "CHF", "GBP"]], envVar: "PROVIDER_OCTOPART_CURRENCY")]
|
||||
#[Assert\Currency()]
|
||||
public string $currency = "EUR";
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, envVar: "PROVIDER_OCTOPART_COUNTRY")]
|
||||
#[Assert\Country]
|
||||
public string $country = "DE";
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.octopart.searchLimit"), description: new TM("settings.ips.octopart.searchLimit.help"),
|
||||
formType: NumberType::class, formOptions: ["attr" => ["min" => 1, "max" => 100]], envVar: "PROVIDER_OCTOPART_SEARCH_LIMIT")]
|
||||
#[Assert\Range(min: 1, max: 100)]
|
||||
public int $searchLimit = 10;
|
||||
|
||||
#[SettingsParameter(label: new TM("settings.ips.octopart.onlyAuthorizedSellers"), description: new TM("settings.ips.octopart.onlyAuthorizedSellers.help"))]
|
||||
public bool $onlyAuthorizedSellers = true;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue