refactor(services): Documents→Document + ExchangeRate→Integrations/ExchangeRate

Two follow-ups to the Services reorg that landed in 6d1816bd.

**Documents → Document** (singular). Documents/ was the only plural subdir in app/Services/ — every other bucket (Company, Mail, Module, Pdf, Storage, Update, ExchangeRate) was singular. Renaming to Document/ normalizes the whole tree.

**ExchangeRate → Integrations/ExchangeRate**. Introduces Integrations/ as an umbrella for external-service adapter subsystems. Exchange rate providers move in first; AI providers, payment gateways, and any other driver-pattern integrations land as sibling subdirs (Integrations/Ai/, Integrations/Payment/) without another reorg. Integrations/ was chosen over Providers/ to avoid conceptual collision with Laravel's app/Providers/ — 'check the providers' shouldn't be ambiguous.

17 files moved, 21 consumer files rewritten to point at the new namespaces via literal-string replacement (same approach as the previous reorg). 350 tests pass, Pint clean.
This commit is contained in:
Darko Gjorgjijoski
2026-04-11 11:30:00 +02:00
parent 6d1816bd1b
commit 947d00a9f1
37 changed files with 47 additions and 47 deletions

View File

@@ -0,0 +1,120 @@
<?php
namespace App\Services\Integrations\ExchangeRate;
use App\Http\Requests\ExchangeRateProviderRequest;
use App\Models\CompanySetting;
use App\Models\ExchangeRateLog;
use App\Models\ExchangeRateProvider;
use App\Services\Integrations\ExchangeRate\ExchangeRateDriverFactory;
use App\Services\Integrations\ExchangeRate\ExchangeRateException;
class ExchangeRateProviderService
{
public function create(ExchangeRateProviderRequest $request): ExchangeRateProvider
{
return ExchangeRateProvider::create($request->getExchangeRateProviderPayload());
}
public function update(ExchangeRateProvider $provider, ExchangeRateProviderRequest $request): ExchangeRateProvider
{
$provider->update($request->getExchangeRateProviderPayload());
return $provider;
}
public function checkActiveCurrencies($request)
{
$currencies = $request->currencies;
if (empty($currencies)) {
return collect();
}
$query = ExchangeRateProvider::where('active', true);
foreach ($currencies as $currency) {
$query->orWhere(function ($q) use ($currency) {
$q->where('active', true)
->whereJsonContains('currencies', $currency);
});
}
return $query->get();
}
public function checkUpdateActiveCurrencies(ExchangeRateProvider $provider, $request)
{
$currencies = $request->currencies;
if (empty($currencies)) {
return collect();
}
$query = ExchangeRateProvider::where('id', '<>', $provider->id)
->where('active', true);
$query->where(function ($q) use ($currencies) {
foreach ($currencies as $currency) {
$q->orWhereJsonContains('currencies', $currency);
}
});
return $query->get();
}
public function checkProviderStatus($request)
{
try {
$driver = ExchangeRateDriverFactory::make(
$request['driver'],
$request['key'],
$request['driver_config'] ?? []
);
$rates = $driver->validateConnection();
return response()->json([
'exchangeRate' => $rates,
], 200);
} catch (ExchangeRateException $e) {
return respondJson($e->errorKey, $e->getMessage());
}
}
public function getExchangeRate(string $driver, string $apiKey, array $driverConfig, string $baseCurrency, string $targetCurrency)
{
try {
$driverInstance = ExchangeRateDriverFactory::make($driver, $apiKey, $driverConfig);
return response()->json([
'exchangeRate' => $driverInstance->getExchangeRate($baseCurrency, $targetCurrency),
], 200);
} catch (ExchangeRateException $e) {
return respondJson($e->errorKey, $e->getMessage());
}
}
public function getSupportedCurrencies(string $driver, string $apiKey, array $driverConfig = [])
{
try {
$driverInstance = ExchangeRateDriverFactory::make($driver, $apiKey, $driverConfig);
return response()->json([
'supportedCurrencies' => $driverInstance->getSupportedCurrencies(),
]);
} catch (ExchangeRateException $e) {
return respondJson($e->errorKey, $e->getMessage());
}
}
public function addExchangeRateLog($model): ExchangeRateLog
{
return ExchangeRateLog::create([
'exchange_rate' => $model->exchange_rate,
'company_id' => $model->company_id,
'base_currency_id' => $model->currency_id,
'currency_id' => CompanySetting::getSetting('currency', $model->company_id),
]);
}
}