feat: add bulk delete with validation to IP Pool and update provisioning logic and email notifications

This commit is contained in:
pbao9
2026-05-13 15:41:56 +07:00
parent 1bbba4e158
commit ae3b681aaa
8 changed files with 242 additions and 101 deletions
@@ -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'])