Added importer details endpoint

This commit is contained in:
Constantin Graf
2024-04-16 16:52:13 +02:00
committed by Gregor Vostrak
parent fe61a54c35
commit 1f79d5e50a
15 changed files with 180 additions and 9 deletions

View File

@@ -6,6 +6,8 @@ namespace App\Http\Controllers\Api\V1;
use App\Http\Requests\V1\Import\ImportRequest;
use App\Models\Organization;
use App\Service\Import\Importers\ImporterContract;
use App\Service\Import\Importers\ImporterProvider;
use App\Service\Import\Importers\ImportException;
use App\Service\Import\ImportService;
use Illuminate\Auth\Access\AuthorizationException;
@@ -13,6 +15,39 @@ use Illuminate\Http\JsonResponse;
class ImportController extends Controller
{
/**
* Get information about available importers
*
* @operationId getImporters
*
* @throws AuthorizationException
*
* @response array{data: array<array{ key: string, name: string, description: string }>}
*/
public function index(Organization $organization, ImporterProvider $importerProvider): JsonResponse
{
$this->checkPermission($organization, 'import');
$importers = $importerProvider->getImporters();
/** @var array<array{ key: string, name: string, description: string }> $importersResponse */
$importersResponse = [];
foreach ($importers as $key => $importerClass) {
/** @var ImporterContract $importer */
$importer = new $importerClass();
$importersResponse[] = [
'key' => $key,
'name' => $importer->getName(),
'description' => $importer->getDescription(),
];
}
return new JsonResponse([
'data' => $importersResponse,
], 200);
}
/**
* Import data into the organization
*