feat: Add DNS management resources and importer
- Implemented DomainCollection, DomainDetailResource, DomainNSCollection, DomainNSResource, and DomainResource for handling DNS domain and record data. - Created VpsServiceCollection and VpsServiceResource for VPS service management. - Added DnsManagerNS and DnsManagerUser models to represent DNS records and user associations. - Developed AdminZoneDnsSqlImporter for importing DNS data from SQL dumps, including customer and DNS domain records. - Added migration scripts to update the customers table with new fields and sync foreign key references for DNS tables. - Created a migration preview document outlining the mapping and schema changes for the admin zone DNS import.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
namespace App\Http\Controllers\Api\Client\Service;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Service\VpsServiceCollection;
|
||||
use App\Http\Resources\Api\Client\Service\ServiceClientDetailResource;
|
||||
use \App\Http\Resources\Api\Client\Service\ServiceClientResource;
|
||||
use App\Http\Services\vCenter;
|
||||
use App\Models\Order;
|
||||
use App\Models\Service;
|
||||
@@ -31,22 +31,75 @@ class ServiceController extends Controller
|
||||
$this->activityLogger = $activityLogger;
|
||||
}
|
||||
|
||||
public function getService(Request $request)
|
||||
public function indexVps(Request $request): JsonResponse
|
||||
{
|
||||
$limit = $request->get('limit', 10);
|
||||
$services = $this->serviceClientService->getActiveServices($limit);
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
$customer = $request->user();
|
||||
|
||||
return ServiceClientResource::collection($services)->additional([
|
||||
$services = $this->serviceClientService->getActiveServices($customer->id, 'vps', $perPage);
|
||||
|
||||
return (new VpsServiceCollection($services))
|
||||
->additional([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'page_type' => 'service_vps',
|
||||
])
|
||||
->response();
|
||||
}
|
||||
|
||||
public function indexHosting(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'page_type' => 'service',
|
||||
'page_type' => 'service_hosting',
|
||||
'data' => [
|
||||
'items' => [],
|
||||
'pagination' => [
|
||||
'total' => 0,
|
||||
'per_page' => $perPage,
|
||||
'current_page' => 1,
|
||||
'last_page' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function indexWebDesign(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Lấy dữ liệu thành công',
|
||||
'page_type' => 'service_web_design',
|
||||
'data' => [
|
||||
'items' => [],
|
||||
'pagination' => [
|
||||
'total' => 0,
|
||||
'per_page' => $perPage,
|
||||
'current_page' => 1,
|
||||
'last_page' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getDetail(Request $request, string $uuid)
|
||||
{
|
||||
$service = $this->serviceClientService->getDetailService($uuid);
|
||||
$service = $this->serviceClientService->getDetailService($uuid, $request->user()->id);
|
||||
|
||||
if (!$service) {
|
||||
return response()->json(
|
||||
[
|
||||
'error' => true,
|
||||
'message' => 'Không tìm thấy dịch vụ',
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
return (new ServiceClientDetailResource($service))->additional([
|
||||
'error' => false,
|
||||
@@ -113,7 +166,7 @@ class ServiceController extends Controller
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'error' => false,
|
||||
'message' => $ticket,
|
||||
]);
|
||||
}
|
||||
@@ -188,7 +241,7 @@ class ServiceController extends Controller
|
||||
$customer = $request->user();
|
||||
|
||||
$service = Service::with([
|
||||
'product.osVersions' => fn ($q) => $q->where('status', 1)->with('osGroup'),
|
||||
'product.osVersions' => fn($q) => $q->where('status', 1)->with('osGroup'),
|
||||
])
|
||||
->where('uuid', $uuid)
|
||||
->where('customer_id', $customer->id)
|
||||
@@ -199,7 +252,10 @@ class ServiceController extends Controller
|
||||
}
|
||||
|
||||
if (!in_array($service->status, ['active', 'suspended'], true)) {
|
||||
return response()->json(['success' => false, 'message' => 'Dịch vụ không ở trạng thái hợp lệ để xem OS'], 422);
|
||||
return response()->json(
|
||||
['success' => false, 'message' => 'Dịch vụ không ở trạng thái hợp lệ để xem OS'],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
if (!$service->product) {
|
||||
@@ -207,32 +263,38 @@ class ServiceController extends Controller
|
||||
}
|
||||
|
||||
$grouped = $service->product->osVersions
|
||||
->groupBy(fn ($os) => $os->osGroup?->id ?? 0)
|
||||
->map(fn ($items) => [
|
||||
'group' => [
|
||||
'id' => $items->first()->osGroup?->id,
|
||||
'name' => $items->first()->osGroup?->name,
|
||||
'thumbnail' => $items->first()->osGroup?->thumbnail,
|
||||
->groupBy(fn($os) => $os->osGroup?->id ?? 0)
|
||||
->map(
|
||||
fn($items) => [
|
||||
'group' => [
|
||||
'id' => $items->first()->osGroup?->id,
|
||||
'name' => $items->first()->osGroup?->name,
|
||||
'thumbnail' => $items->first()->osGroup?->thumbnail,
|
||||
],
|
||||
'items' => $items
|
||||
->map(
|
||||
fn($os) => [
|
||||
'id' => $os->id,
|
||||
'version' => $os->version,
|
||||
'template_id' => $os->template_id,
|
||||
],
|
||||
)
|
||||
->values(),
|
||||
],
|
||||
'items' => $items->map(fn ($os) => [
|
||||
'id' => $os->id,
|
||||
'version' => $os->version,
|
||||
'template_id' => $os->template_id,
|
||||
])->values(),
|
||||
])
|
||||
)
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $grouped,
|
||||
'data' => $grouped,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rebuild(Request $request, string $uuid, vCenter $serviceVCenter): JsonResponse
|
||||
{
|
||||
$customer = $request->user();
|
||||
$payload = $request->validate([
|
||||
'os_id' => ['required', 'integer', 'exists:os,id'],
|
||||
$payload = $request->validate([
|
||||
'os_id' => ['required', 'integer', 'exists:os,id'],
|
||||
'password' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
@@ -246,18 +308,18 @@ class ServiceController extends Controller
|
||||
}
|
||||
|
||||
if ($service->status === 'suspended') {
|
||||
return response()->json(['success' => false, 'message' => 'Dịch vụ đang bị tạm ngưng, không thể rebuild'], 422);
|
||||
return response()->json(
|
||||
['success' => false, 'message' => 'Dịch vụ đang bị tạm ngưng, không thể rebuild'],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
if (!$service->isActive()) {
|
||||
return response()->json(['success' => false, 'message' => 'Dịch vụ không ở trạng thái active'], 422);
|
||||
}
|
||||
|
||||
$allowedOsIds = $service->product?->osVersions()
|
||||
->where('status', 1)
|
||||
->pluck('os.id')
|
||||
->map('intval')
|
||||
->toArray() ?? [];
|
||||
$allowedOsIds =
|
||||
$service->product?->osVersions()->where('status', 1)->pluck('os.id')->map('intval')->toArray() ?? [];
|
||||
|
||||
if (!in_array((int) $payload['os_id'], $allowedOsIds, true)) {
|
||||
return response()->json(['success' => false, 'message' => 'OS không hợp lệ cho sản phẩm hiện tại'], 422);
|
||||
@@ -269,31 +331,34 @@ class ServiceController extends Controller
|
||||
}
|
||||
|
||||
DB::table('reinstall_logs')->insert([
|
||||
'product_id' => $vm->id,
|
||||
'product_id' => $vm->id,
|
||||
'product_type' => 4,
|
||||
'custome_id' => $customer->id,
|
||||
'os_id' => $payload['os_id'],
|
||||
'status' => 'pending',
|
||||
'initiator' => 'client',
|
||||
'note' => 'Client rebuild via service UUID: ' . $uuid,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'custome_id' => $customer->id,
|
||||
'os_id' => $payload['os_id'],
|
||||
'status' => 'pending',
|
||||
'initiator' => 'client',
|
||||
'note' => 'Client rebuild via service UUID: ' . $uuid,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$result = $serviceVCenter->reBuildVPS((string) $vm->name);
|
||||
if (is_string($result) || ($result['error'] ?? false)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => is_string($result) ? $result : ($result['message'] ?? 'Không thể rebuild VM'),
|
||||
], 400);
|
||||
return response()->json(
|
||||
[
|
||||
'success' => false,
|
||||
'message' => is_string($result) ? $result : $result['message'] ?? 'Không thể rebuild VM',
|
||||
],
|
||||
400,
|
||||
);
|
||||
}
|
||||
|
||||
$this->activityLogger->log(
|
||||
event: 'rebuild',
|
||||
logName: 'VM',
|
||||
event: 'rebuild',
|
||||
logName: 'VM',
|
||||
description: "Customer {$customer->email} rebuild VM: {$vm->name} với OS ID: {$payload['os_id']} qua service UUID: {$uuid}",
|
||||
subject: $vm,
|
||||
newValues: ['os_id' => $payload['os_id'], 'service_uuid' => $uuid],
|
||||
subject: $vm,
|
||||
newValues: ['os_id' => $payload['os_id'], 'service_uuid' => $uuid],
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
@@ -301,5 +366,4 @@ class ServiceController extends Controller
|
||||
'message' => 'Đã gửi yêu cầu rebuild VM',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user