feat: add bulk delete with validation to IP Pool and update provisioning logic and email notifications
This commit is contained in:
@@ -240,6 +240,42 @@ class IpPoolController extends Controller
|
||||
return response()->json(['error' => false, 'message' => 'Đã xoá IP Pool thành công']);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'ids' => 'required|array|min:1',
|
||||
'ids.*' => 'integer',
|
||||
]);
|
||||
|
||||
$ids = $request->ids;
|
||||
$pools = IpPool::whereIn('id', $ids)->get();
|
||||
|
||||
if ($pools->isEmpty()) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy IP Pool nào'], 404);
|
||||
}
|
||||
|
||||
// Block deletion if any IP is currently assigned
|
||||
$inUseIps = ModuleIpAddress::whereIn('ip', $pools->pluck('ip_address'))
|
||||
->where('status', 1)
|
||||
->pluck('ip')
|
||||
->toArray();
|
||||
|
||||
if (!empty($inUseIps)) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Không thể xoá — các IP sau đang được gán cho máy chủ: ' . implode(', ', $inUseIps),
|
||||
], 422);
|
||||
}
|
||||
|
||||
$deleted = IpPool::whereIn('id', $ids)->delete();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => "Đã xoá {$deleted} IP Pool thành công",
|
||||
'deleted' => $deleted,
|
||||
]);
|
||||
}
|
||||
|
||||
public function networks(): JsonResponse
|
||||
{
|
||||
$networks = ModuleNetwork::select(['id', 'name', 'type', 'network'])
|
||||
|
||||
Reference in New Issue
Block a user