diff --git a/app/Http/Controllers/Api/Admin/VCenter/VCenterController.php b/app/Http/Controllers/Api/Admin/VCenter/VCenterController.php index 43095e7d..b5357fe 100644 --- a/app/Http/Controllers/Api/Admin/VCenter/VCenterController.php +++ b/app/Http/Controllers/Api/Admin/VCenter/VCenterController.php @@ -93,6 +93,43 @@ class VCenterController extends Controller ]); } + public function storeNode(Request $request, string $type): JsonResponse + { + $rules = match ($type) { + 'datacenter' => [ + 'vcenter_id' => 'required|integer|exists:module_vcenter,id', + 'name' => 'required|string|max:255', + 'datacenter_id' => 'nullable|string|max:255', + ], + 'host' => [ + 'module_datacenter_id' => 'required|integer|exists:module_datacenter,id', + 'name' => 'required|string|max:255', + 'host_id' => 'nullable|string|max:255', + 'template' => 'nullable|string|max:500', + 'console' => 'nullable|string|max:500', + 'iso_path' => 'nullable|string|max:500', + ], + 'network' => [ + 'module_host_id' => 'required|integer|exists:module_host,id', + 'name' => 'required|string|max:255', + 'network' => 'nullable|string|max:255', + 'type' => 'nullable|string|max:255', + ], + default => abort(422, 'Không hỗ trợ tạo node loại này'), + }; + + $data = $request->validate($rules); + $data['status'] = 1; + + $model = match ($type) { + 'datacenter' => ModuleDatacenter::create($data), + 'host' => ModuleHost::create($data), + 'network' => ModuleNetwork::create($data), + }; + + return response()->json(['error' => false, 'data' => $model], 201); + } + public function updateNode(Request $request, string $type, int $id): JsonResponse { $model = $this->resolveModel($type, $id); diff --git a/app/Http/Controllers/Api/Client/Service/ServiceController.php b/app/Http/Controllers/Api/Client/Service/ServiceController.php index 7a663cb..60dea42 100644 --- a/app/Http/Controllers/Api/Client/Service/ServiceController.php +++ b/app/Http/Controllers/Api/Client/Service/ServiceController.php @@ -293,6 +293,40 @@ class ServiceController extends Controller ]); } + public function updateAutoRenew(Request $request, string $uuid): JsonResponse + { + $validated = $request->validate(['auto_renew' => ['required', 'boolean']]); + + $service = Service::query() + ->where('uuid', $uuid) + ->where('customer_id', $request->user()->id) + ->first(); + + if (! $service) { + return response()->json(['error' => true, 'message' => 'Không tìm thấy dịch vụ'], 404); + } + + $service->update(['auto_renew' => (bool) $validated['auto_renew']]); + + $this->activityLogger->log( + event: 'updated', + logName: 'Service', + description: "Customer {$request->user()->email} " . ($validated['auto_renew'] ? 'bật' : 'tắt') . " tự động gia hạn dịch vụ #{$service->id}", + subject: $service, + newValues: ['auto_renew' => (bool) $validated['auto_renew']], + ); + + return response()->json([ + 'error' => false, + 'message' => 'Cập nhật tự động gia hạn thành công.', + 'data' => [ + 'uuid' => $service->uuid, + 'id' => $service->id, + 'auto_renew' => (bool) $service->auto_renew, + ], + ]); + } + public function rebuild(Request $request, string $uuid, VmRebuildService $rebuildService): JsonResponse { $customer = $request->user(); diff --git a/routes/api.php b/routes/api.php index 66353ae..a7ae784 100644 --- a/routes/api.php +++ b/routes/api.php @@ -324,6 +324,7 @@ Route::prefix('v1') Route::get('console-ticket', 'consoleTicket')->middleware('perm:module-vcenter.view'); Route::post('/', 'store')->middleware('perm:module-vcenter.create'); Route::post('sync', 'sync')->middleware('perm:module-vcenter.edit'); + Route::post('node/{type}', 'storeNode')->middleware('perm:module-vcenter.create'); Route::put('node/{type}/{id}', 'updateNode')->middleware('perm:module-vcenter.edit'); Route::delete('node/{type}/{id}', 'destroyNode')->middleware('perm:module-vcenter.destroy'); }); diff --git a/routes/client.php b/routes/client.php index b33cc55..4c55a95 100644 --- a/routes/client.php +++ b/routes/client.php @@ -83,6 +83,7 @@ Route::prefix('v1') Route::get('{uuid}/console-ticket', 'getConsoleTicket')->name('console-ticket'); Route::get('{uuid}/available-os', 'getAvailableOs')->name('available-os'); Route::post('{uuid}/rebuild', 'rebuild')->name('rebuild'); + Route::patch('{uuid}/auto-renew', 'updateAutoRenew')->name('auto-renew.update'); }); Route::middleware(['api.auth'])