2024-03-07 10:14:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2024-06-18 18:59:39 +00:00
|
|
|
use App\Models\Application;
|
2024-03-07 10:14:03 +00:00
|
|
|
use Illuminate\Http\Request;
|
2024-06-18 18:59:39 +00:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
2024-03-07 10:14:03 +00:00
|
|
|
|
|
|
|
class Domains extends Controller
|
|
|
|
{
|
2024-06-18 18:59:39 +00:00
|
|
|
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(),
|
2024-06-18 18:59:39 +00:00
|
|
|
], 422);
|
|
|
|
}
|
|
|
|
|
|
|
|
$application = Application::where('uuid', $request->uuid)->first();
|
|
|
|
|
2024-06-19 07:07:49 +00:00
|
|
|
if (! $application) {
|
2024-06-18 18:59:39 +00:00
|
|
|
return response()->json([
|
|
|
|
'success' => false,
|
2024-06-19 07:07:49 +00:00
|
|
|
'message' => 'Application not found',
|
2024-06-18 18:59:39 +00:00
|
|
|
], 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)));
|
2024-06-18 18:59:39 +00:00
|
|
|
$application->save();
|
2024-06-19 07:07:49 +00:00
|
|
|
|
2024-06-18 18:59:39 +00:00
|
|
|
return response()->json([
|
|
|
|
'success' => true,
|
|
|
|
'message' => 'Domains updated successfully',
|
2024-06-19 07:07:49 +00:00
|
|
|
'application' => $application,
|
2024-06-18 18:59:39 +00:00
|
|
|
]);
|
|
|
|
}
|
2024-03-07 10:14:03 +00:00
|
|
|
}
|