wowowowowo
This commit is contained in:
@@ -4,13 +4,27 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\RegistryType;
|
||||
use App\Http\Requests\StoreRegistryRequest;
|
||||
use App\Http\Requests\UpdateRegistryRequest;
|
||||
use App\Models\BuildArtifact;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Registry;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
|
||||
class RegistryController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
|
||||
return inertia('registries/Index', [
|
||||
'registries' => $organisation->registries()
|
||||
->latest()
|
||||
->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
Organisation::findOrFail($request->route('organisation'));
|
||||
@@ -38,4 +52,75 @@ class RegistryController extends Controller
|
||||
->route('organisations.show', ['organisation' => $organisation->id])
|
||||
->with('success', 'Registry created.');
|
||||
}
|
||||
|
||||
public function show(Request $request): Response
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
/** @var Registry $registry */
|
||||
$registry = $organisation->registries()->findOrFail($request->route('registry'));
|
||||
$registryUrl = rtrim((string) $registry->url, '/');
|
||||
$artifacts = BuildArtifact::query()
|
||||
->with(['environment.application', 'builtByService'])
|
||||
->whereHas('environment.application', fn ($query) => $query->where('organisation_id', $organisation->id))
|
||||
->when($registryUrl !== '', fn ($query) => $query->where('registry_ref', 'like', $registryUrl.'%'));
|
||||
|
||||
return inertia('registries/Show', [
|
||||
'registry' => $registry,
|
||||
'artifactCount' => (clone $artifacts)->count(),
|
||||
'environmentCount' => (clone $artifacts)->distinct('environment_id')->count('environment_id'),
|
||||
'artifacts' => $artifacts
|
||||
->latest()
|
||||
->paginate(20),
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Request $request): Response
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$registry = $organisation->registries()->findOrFail($request->route('registry'));
|
||||
|
||||
return inertia('registries/Edit', [
|
||||
'registry' => $registry,
|
||||
'registryTypes' => array_values(RegistryType::toArray()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdateRegistryRequest $request): RedirectResponse
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
/** @var Registry $registry */
|
||||
$registry = $organisation->registries()->findOrFail($request->route('registry'));
|
||||
|
||||
$credentials = $registry->credentials ?? [];
|
||||
$username = $request->string('username')->toString();
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$credentials['password'] = $request->string('password')->toString();
|
||||
}
|
||||
|
||||
$credentials['username'] = $username;
|
||||
|
||||
$registry->update([
|
||||
'name' => $request->string('name')->toString(),
|
||||
'type' => $request->enum('type', RegistryType::class),
|
||||
'url' => rtrim($request->string('url')->toString(), '/'),
|
||||
'credentials' => $credentials,
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->route('organisations.show', ['organisation' => $organisation->id])
|
||||
->with('success', 'Registry updated.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$organisation = Organisation::findOrFail($request->route('organisation'));
|
||||
$registry = $organisation->registries()->findOrFail($request->route('registry'));
|
||||
|
||||
$registry->delete();
|
||||
|
||||
return redirect()
|
||||
->route('organisations.show', ['organisation' => $organisation->id])
|
||||
->with('success', 'Registry deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user