You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Cloud/CloudTemplateImportReadMode...

38 lines
1.1 KiB
PHP

<?php
namespace App\Services\Cloud;
use App\Models\CloudTemplateImportIntent;
/** Provides administrator-safe projections of import intent state. */
final class CloudTemplateImportReadModel extends CloudTemplateImportModule
{
public function active(array $actor): array
{
self::assertAdministrator($actor);
$rows = CloudTemplateImportIntent::query()
->whereNotIn('state', ['ready', 'cancelled'])
->orderByDesc('created_at')->limit(50)->get();
return ['intents' => $rows->map(
static fn (CloudTemplateImportIntent $row): array => self::dto($row)
)->all()];
}
public function one(string $id, array $actor): array
{
self::assertAdministrator($actor);
$id = self::intentId($id);
$intent = CloudTemplateImportIntent::find($id);
if ($intent === null) {
throw new CloudError('云镜像导入记录不存在', 404);
}
return ['intent' => self::dto($intent)];
}
/** @return array<string,mixed> */
public static function project(CloudTemplateImportIntent $intent): array
{
return self::dto($intent);
}
}