Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| IntegrationController | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\Admin; |
| 4 | |
| 5 | use App\Enums\IntegrationStatus; |
| 6 | use App\Http\Controllers\Concerns\ResolvesContext; |
| 7 | use App\Http\Controllers\Controller; |
| 8 | use App\Models\IntegrationProvider; |
| 9 | use App\Models\StoreIntegration; |
| 10 | use Illuminate\Http\RedirectResponse; |
| 11 | use Illuminate\Http\Request; |
| 12 | use Illuminate\View\View; |
| 13 | |
| 14 | class IntegrationController extends Controller |
| 15 | { |
| 16 | use ResolvesContext; |
| 17 | |
| 18 | public function index(): View |
| 19 | { |
| 20 | return view('admin.integrations.index', [ |
| 21 | 'integrations' => StoreIntegration::with('provider')->where('store_id', $this->currentStore()->id)->get(), |
| 22 | 'providers' => IntegrationProvider::where('status', 'active')->get(), |
| 23 | ]); |
| 24 | } |
| 25 | |
| 26 | public function update(Request $request, StoreIntegration $integration): RedirectResponse |
| 27 | { |
| 28 | $data = $request->validate([ |
| 29 | 'external_store_id' => ['nullable', 'string', 'max:255'], |
| 30 | 'access_token' => ['nullable', 'string'], |
| 31 | 'refresh_token' => ['nullable', 'string'], |
| 32 | 'scopes' => ['nullable', 'string'], |
| 33 | 'status' => ['required', 'string'], |
| 34 | ]); |
| 35 | |
| 36 | $integration->update([ |
| 37 | 'external_store_id' => $data['external_store_id'] ?? null, |
| 38 | 'access_token' => $data['access_token'] ?: $integration->access_token, |
| 39 | 'refresh_token' => $data['refresh_token'] ?: $integration->refresh_token, |
| 40 | 'scopes' => filled($data['scopes'] ?? null) ? array_map('trim', explode(',', $data['scopes'])) : $integration->scopes, |
| 41 | 'status' => IntegrationStatus::from($data['status']), |
| 42 | 'installed_at' => $data['status'] === IntegrationStatus::Connected->value ? now() : $integration->installed_at, |
| 43 | ]); |
| 44 | |
| 45 | return back()->with('success', 'Integração atualizada.'); |
| 46 | } |
| 47 | } |