Files
portal-api/app/Repositories/DnsManager/Domain/DnsDomainRepository.php
T
baodev0 fccb0c353a 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.
2026-05-26 13:54:33 +07:00

90 lines
2.9 KiB
PHP

<?php
namespace App\Repositories\DnsManager\Domain;
use App\Models\DnsDomain;
use App\Repositories\BaseRepository;
class DnsDomainRepository extends BaseRepository implements DnsDomainRepositoryInterface
{
public function getModel(): string
{
return DnsDomain::class;
}
public function findDomain(string $domain = '')
{
return $this->model->where('domain_name', $domain)->first();
}
public function filter(array $data = [], array $relationships = [], string $order = 'id', array $select = ['*'])
{
$model = $this->model;
if (count($relationships)) {
$model = $model->with($relationships);
}
if (isset($data['q']) && $data['q']) {
$model = $model->where('domain_name', 'like', '%' . $data['q'] . '%');
}
if (isset($data['search']['value']) && $data['search']['value']) {
$model = $model->where('domain_name', 'like', '%' . $data['search']['value'] . '%');
}
if (isset($data['user_id']) && $data['user_id']) {
$model = $model->whereHas('users', function ($query) use ($data) {
$query->where('customers.id', $data['user_id']);
});
}
if (isset($data['limit']) && !isset($data['page']) && $data['limit']) {
$model = $model->take($data['limit']);
}
if (isset($data['relations'])) {
foreach ($data['relations'] as $key => $value) {
$model = $model->whereHas($key, function ($query) use ($value) {
if (isset($value['condition'])) {
switch (strtoupper($value['condition'])) {
case 'IN':
$query->whereIn($value['key'], $value['value']);
break;
case 'NOTIN':
$query->whereNotIn($value['key'], $value['value']);
break;
default:
$query->where($value['key'], $value['condition'], $value['value']);
}
} else {
$query->where($value['key'], $value['value']);
}
});
}
}
$model = $model->select($select)->orderByDesc($order);
if (isset($data['start'])) {
return $model->offset($data['start'])->limit($data['length'] ?? 10)->get();
}
if (isset($data['page'])) {
return $model->paginate($data['length'] ?? 12);
}
return $model->get();
}
public function findWhereIn(string $key, array $value = [])
{
return $this->model->whereIn($key, $value)->get();
}
public function findWithRelations(int $id, array $relationships = [])
{
return $this->model->with($relationships)->find($id);
}
}