lasthourcloud/app/Http/Controllers/Api/Domains.php

55 lines
1.7 KiB
PHP
Raw Normal View History

2024-03-07 10:14:03 +00:00
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Application;
2024-03-07 10:14:03 +00:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
2024-03-07 10:14:03 +00:00
class Domains extends Controller
{
public function deleteDomains(Request $request)
{
$teamId = get_team_id_from_token();
if (is_null($teamId)) {
return invalid_token();
}
$validator = Validator::make($request->all(), [
'uuid' => 'required|string|exists:applications,uuid',
'domains' => 'required|array',
'domains.*' => 'required|string|distinct',
]);
if ($validator->fails()) {
return response()->json([
'success' => false,
'message' => 'Validation failed',
2024-06-19 07:07:49 +00:00
'errors' => $validator->errors(),
], 422);
}
$application = Application::where('uuid', $request->uuid)->first();
2024-06-19 07:07:49 +00:00
if (! $application) {
return response()->json([
'success' => false,
2024-06-19 07:07:49 +00:00
'message' => 'Application not found',
], 404);
}
$existingDomains = explode(',', $application->fqdn);
$domainsToDelete = $request->domains;
$updatedDomains = array_diff($existingDomains, $domainsToDelete);
$application->fqdn = implode(',', $updatedDomains);
2024-06-18 19:35:33 +00:00
$application->custom_labels = base64_encode(implode("\n ", generateLabelsApplication($application)));
$application->save();
2024-06-19 07:07:49 +00:00
return response()->json([
'success' => true,
'message' => 'Domains updated successfully',
2024-06-19 07:07:49 +00:00
'application' => $application,
]);
}
2024-03-07 10:14:03 +00:00
}