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:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class DomainCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = DomainResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
'items' => $this->collection,
|
||||
];
|
||||
|
||||
if (method_exists($this->resource, 'total')) {
|
||||
$data['pagination'] = [
|
||||
'total' => $this->resource->total(),
|
||||
'per_page' => $this->resource->perPage(),
|
||||
'current_page' => $this->resource->currentPage(),
|
||||
'last_page' => $this->resource->lastPage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainDetailResource extends JsonResource
|
||||
{
|
||||
public function __construct($resource, protected mixed $records = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'domain' => new DomainResource($this->resource),
|
||||
'ns_count' => (int) ($this->record_count ?? 0),
|
||||
'records' => $this->records ? new DomainNSCollection($this->records) : [
|
||||
'items' => [],
|
||||
'pagination' => [
|
||||
'total' => 0,
|
||||
'per_page' => 0,
|
||||
'current_page' => 1,
|
||||
'last_page' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class DomainNSCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = DomainNSResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
'items' => $this->collection,
|
||||
];
|
||||
|
||||
if (method_exists($this->resource, 'total')) {
|
||||
$data['pagination'] = [
|
||||
'total' => $this->resource->total(),
|
||||
'per_page' => $this->resource->perPage(),
|
||||
'current_page' => $this->resource->currentPage(),
|
||||
'last_page' => $this->resource->lastPage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainNSResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'dns_manager_domain_id' => $this->dns_manager_domain_id,
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'type_valid' => $this->type_valid,
|
||||
'priority' => $this->priority,
|
||||
'weight' => $this->weight,
|
||||
'port' => $this->port,
|
||||
'service_name' => $this->service_name,
|
||||
'protocol' => $this->protocol,
|
||||
'value' => $this->value,
|
||||
'ttl' => isset($this->ttl) ? (int) $this->ttl : null,
|
||||
'plesk_id' => $this->plesk_id,
|
||||
'created_at' => optional($this->created_at)->toISOString(),
|
||||
'updated_at' => optional($this->updated_at)->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'domain_name' => $this->domain_name,
|
||||
'dns_manager_server_id' => $this->dns_manager_server_id,
|
||||
'server_name' => $this->server?->name,
|
||||
'server_ip' => $this->server?->ip_address,
|
||||
'is_created' => isset($this->is_created) ? (int) $this->is_created : null,
|
||||
'plesk_id' => $this->plesk_id,
|
||||
'record_count' => $this->whenCounted('record'),
|
||||
'created_at' => optional($this->created_at)->toISOString(),
|
||||
'updated_at' => optional($this->updated_at)->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class VpsServiceCollection extends ResourceCollection
|
||||
{
|
||||
public $collects = VpsServiceResource::class;
|
||||
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = [
|
||||
'items' => $this->collection,
|
||||
];
|
||||
|
||||
if (method_exists($this->resource, 'total')) {
|
||||
$data['pagination'] = [
|
||||
'total' => $this->resource->total(),
|
||||
'per_page' => $this->resource->perPage(),
|
||||
'current_page' => $this->resource->currentPage(),
|
||||
'last_page' => $this->resource->lastPage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\Service;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class VpsServiceResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$orderItem = $this->orderItem;
|
||||
$product = $orderItem?->product;
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'server_name' => $this->server_name,
|
||||
'status' => $this->status,
|
||||
'status_label' => $this->status_label,
|
||||
'auto_renew' => (bool) $this->auto_renew,
|
||||
'started_at' => $this->started_at?->toISOString(),
|
||||
'expires_at' => $this->expires_at?->toISOString(),
|
||||
'os' => [
|
||||
'version' => $orderItem?->os?->version,
|
||||
'group' => $orderItem?->os?->osGroup?->name,
|
||||
],
|
||||
'product' => $product ? [
|
||||
'id' => $product->id,
|
||||
'name' => $product->name,
|
||||
'slug' => $product->slug,
|
||||
'product_type' => $product->product_type,
|
||||
'page_type' => 'service_vps',
|
||||
] : null,
|
||||
'specs' => $product ? [
|
||||
'cpu' => (int) ($product->cpu ?? 0),
|
||||
'ram' => (int) ($product->ram ?? 0),
|
||||
'disk' => (int) ($product->disk ?? 0),
|
||||
'bandwidth' => (int) ($product->bandwidth ?? 0),
|
||||
'gpu' => $product->gpu,
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user