- Introduced `livewire.php` for customizable Livewire configuration. - Enhanced ConnectedApp management by adding delete functionality and dynamic navigation handling (`goBack()`). - Updated forms (`create`, `edit`) with `maryUI` components (`mary-form`, `mary-button`, `mary-input`, `mary-choices`). - Consolidated provider imports and refactored UI for reusability and improved styling. - Improved exception handling and validation rules in `ConnectedAppService` and Livewire components.
91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Data\ConnectedApp\{ConnectAppRequest, ConnectedAppData};
|
|
use App\Data\Ui\ConnectedApps\ConnectedAppData as UiConnectedAppData;
|
|
use App\Models\ConnectedApp;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
use Illuminate\Support\Facades\DB;
|
|
use InvalidArgumentException;
|
|
use Spatie\LaravelData\PaginatedDataCollection;
|
|
use Throwable;
|
|
|
|
final class ConnectedAppService
|
|
{
|
|
/**
|
|
* Create a new connected app.
|
|
*
|
|
* @throws Throwable when an error occurs during the creation.
|
|
*/
|
|
public function create(ConnectAppRequest $data): void
|
|
{
|
|
DB::transaction(
|
|
fn () => ConnectedApp::query()->create(
|
|
$data->toArray()
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @throws InvalidArgumentException when id is invalid
|
|
* @throws Throwable when an error occurs during the update.
|
|
*/
|
|
public function update(int $id, ConnectAppRequest $data): void
|
|
{
|
|
if ($id <= 0) {
|
|
throw new InvalidArgumentException('Invalid id');
|
|
}
|
|
DB::transaction(
|
|
fn () => ConnectedApp::query()
|
|
->where('id', $id)
|
|
->update($data->toArray())
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @throws Throwable when an error occurs during the deletion.
|
|
* @throws InvalidArgumentException when id is invalid
|
|
*/
|
|
public function delete(int $id): void
|
|
{
|
|
if ($id <= 0) {
|
|
throw new InvalidArgumentException('Invalid id');
|
|
}
|
|
|
|
DB::transaction(
|
|
fn () => ConnectedApp::query()
|
|
->where('id', $id)
|
|
->delete()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return PaginatedDataCollection<int, UiConnectedAppData>
|
|
*/
|
|
public function getAll(): PaginatedDataCollection
|
|
{
|
|
$data = ConnectedApp::with('provider:name,id', 'protocol:id,name', 'status:id,name')
|
|
->paginate();
|
|
|
|
return UiConnectedAppData::collect($data, PaginatedDataCollection::class);
|
|
}
|
|
|
|
/**
|
|
* @throws ModelNotFoundException<ConnectedApp> when the connected app is not found.
|
|
* @throws InvalidArgumentException when id is invalid.
|
|
*/
|
|
public function getConnectedApp(int $id): ConnectedAppData
|
|
{
|
|
if ($id <= 0) {
|
|
throw new InvalidArgumentException('Invalid id');
|
|
}
|
|
$data = ConnectedApp::with('provider:id', 'protocol:id', 'status:id')
|
|
->findOrFail($id);
|
|
|
|
return ConnectedAppData::from($data);
|
|
}
|
|
}
|