update fix deadcode, security
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Datacenter;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DatacenterCachedRepository extends BaseCachedRepository implements DatacenterRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public DatacenterRepository $datacenterRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->datacenterRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if (
|
||||
$returnQuery ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->datacenterRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->datacenterRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->datacenterRepository->findBy($key, $value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Datacenter;
|
||||
|
||||
use App\Models\ModuleDatacenter;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class DatacenterRepository extends BaseRepository implements DatacenterRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleDatacenter::class;
|
||||
}
|
||||
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$query = $this->model
|
||||
->select($select)
|
||||
->with($relationships);
|
||||
|
||||
if (!empty($data['vcenter_id'])) {
|
||||
$query->where('vcenter_id', $data['vcenter_id']);
|
||||
}
|
||||
|
||||
if (!empty($withCount)) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Datacenter;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface DatacenterRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Datastore;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class DatastoreCachedRepository extends BaseCachedRepository implements DatastoreRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public DatastoreRepository $datastoreRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->datastoreRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if (
|
||||
$returnQuery ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->datastoreRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->datastoreRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() => $this->datastoreRepository->findBy($key, $value)
|
||||
);
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() => $this->datastoreRepository->findWithRelationships($id, $relationships, $withCount, $withSum)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Datastore;
|
||||
|
||||
use App\Models\ModuleDatastore;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class DatastoreRepository extends BaseRepository implements DatastoreRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleDatastore::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$query = $query->where("status", $data['status']);
|
||||
}
|
||||
if (isset($data['module_host_id']) && $data['module_host_id']) {
|
||||
$query->where("module_host_id", $data['module_host_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($relationships) > 0) {
|
||||
$validRelationships = [];
|
||||
foreach ($relationships as $relationship) {
|
||||
$firstRelation = explode('.', $relationship)[0];
|
||||
if (method_exists($model, $firstRelation)) {
|
||||
$validRelationships[] = $relationship;
|
||||
}
|
||||
}
|
||||
if (count($validRelationships) > 0) {
|
||||
$model = $model->with($validRelationships);
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withCount
|
||||
if (count($withCount) > 0) {
|
||||
foreach ($withCount as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withCount([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withCount($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withSum
|
||||
if (count($withSum) > 0) {
|
||||
foreach ($withSum as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withSum([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
], $item['sum']);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withSum($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model->find($id);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Datastore;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface DatastoreRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []);
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Folder;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class FolderCachedRepository extends BaseCachedRepository implements FolderRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public FolderRepository $folderRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->folderRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if (
|
||||
$returnQuery ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->folderRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->folderRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->folderRepository->findBy($key, $value);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) {
|
||||
return $this->folderRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Folder;
|
||||
|
||||
use App\Models\ModuleFolder;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class FolderRepository extends BaseRepository implements FolderRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleFolder::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
|
||||
if (isset($data['module_datacenter_id']) && $data['module_datacenter_id']) {
|
||||
$query->where("module_datacenter_id", $data['module_datacenter_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
return $query->get();
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($relationships) > 0) {
|
||||
foreach ($relationships as $relationship) {
|
||||
if (method_exists($model, $relationship)) {
|
||||
$model = $model->with($relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Xử lý withCount
|
||||
if (count($withCount) > 0) {
|
||||
foreach ($withCount as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withCount([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withCount($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withSum
|
||||
if (count($withSum) > 0) {
|
||||
foreach ($withSum as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withSum([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
], $item['sum']);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withSum($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model->find($id);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Folder;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface FolderRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []);
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Host;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HostCachedRepository extends BaseCachedRepository implements HostRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public HostRepository $hostRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->hostRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if ($returnQuery || isset($data['page']) || isset($data['paginate'])) {
|
||||
return $this->hostRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount, $returnQuery) {
|
||||
return $this->hostRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
||||
return $this->hostRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
||||
});
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->hostRepository->findBy($key, $value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Host;
|
||||
|
||||
use App\Models\ModuleHost;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class HostRepository extends BaseRepository implements HostRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleHost::class;
|
||||
}
|
||||
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['module_datacenter_id']) && $data['module_datacenter_id']) {
|
||||
$query = $query->where("module_datacenter_id", $data['module_datacenter_id']);
|
||||
}
|
||||
|
||||
if (count($withCount) > 0) {
|
||||
$query = $query->withCount($withCount);
|
||||
}
|
||||
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (isset($data['page']) || isset($data['paginate'])) {
|
||||
return $query->paginate($data['per_page'] ?? 15);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($relationships) > 0) {
|
||||
foreach ($relationships as $relationship) {
|
||||
if (method_exists($model, $relationship)) {
|
||||
$model = $model->with($relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Xử lý withCount
|
||||
if (count($withCount) > 0) {
|
||||
foreach ($withCount as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withCount([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withCount($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withSum
|
||||
if (count($withSum) > 0) {
|
||||
foreach ($withSum as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withSum([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
], $item['sum']);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withSum($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model->find($id);
|
||||
}
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Host;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface HostRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = []);
|
||||
public function findBy(string $key = '',string|int|null $value = '' );
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Repositories\Module\HostingServer;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use App\Repositories\BaseRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HostingServerCachedRepository extends BaseCachedRepository implements HostingServerRepositoryInterface
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class IPPoolCachedRepository extends BaseCachedRepository implements IPPoolRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public IPPoolRepository $ipPoolRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->ipPoolRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filterItem' => [
|
||||
'data' => $data,
|
||||
'relationships' => $relationships,
|
||||
'select' => $select,
|
||||
'withCount' => $withCount
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
||||
return $this->ipPoolRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
public function findByName(string $name = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findByName' => [
|
||||
'name' => $name
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($name){
|
||||
return $this->ipPoolRepository->findByName($name);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Models\IPPool;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class IPPoolRepository extends BaseRepository implements IPPoolRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return IPPool::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
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']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$query->where($value['key'], $value['value']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
}
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate(15);
|
||||
}
|
||||
return $model->get();
|
||||
}
|
||||
public function findByName(string $name = '')
|
||||
{
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where('name','LIKE',"%$name%")->first();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface IPPoolRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
public function findByName(string $name = '');
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IpAddress;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class IpAddressCachedRepository extends BaseCachedRepository implements IpAddressRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public IpAddressRepository $ipAddressRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->ipAddressRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if (
|
||||
$returnQuery ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->ipAddressRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->ipAddressRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function updateBy(array $condistions = [], array $data = [])
|
||||
{
|
||||
$this->ipAddressRepository->updateBy($condistions, $data);
|
||||
$this->clearCache();
|
||||
return $this;
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) {
|
||||
return $this->ipAddressRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
|
||||
});
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->ipAddressRepository->findBy($key, $value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IpAddress;
|
||||
|
||||
use App\Models\ModuleIpAddress;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class IpAddressRepository extends BaseRepository implements IpAddressRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleIpAddress::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$query = $query->where("status", $data['status']);
|
||||
}
|
||||
if (isset($data['module_network_id']) && $data['module_network_id']) {
|
||||
$query->where("module_network_id", $data['module_network_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($relationships) > 0) {
|
||||
foreach ($relationships as $relationship) {
|
||||
if (method_exists($model, $relationship)) {
|
||||
$model = $model->with($relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Xử lý withCount
|
||||
if (count($withCount) > 0) {
|
||||
foreach ($withCount as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withCount([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withCount($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withSum
|
||||
if (count($withSum) > 0) {
|
||||
foreach ($withSum as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withSum([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
], $item['sum']);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withSum($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model->find($id);
|
||||
}
|
||||
public function updateBy(array $condistions = [], array $data = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($condistions) > 0) {
|
||||
foreach ($condistions as $key => $value) {
|
||||
$model = $model->where($key, $value);
|
||||
}
|
||||
$model = $model->first();
|
||||
if ($model) {
|
||||
return $model->update($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->isFree()->where($key, $value)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IpAddress;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface IpAddressRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function updateBy(array $condistions = [], array $data = []);
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []);
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Network;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NetworkCachedRepository extends BaseCachedRepository implements NetworkRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public NetworkRepository $networkRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->networkRepository->getModel();
|
||||
}
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
if (
|
||||
$returnQuery ||
|
||||
!empty($data['paginate'])
|
||||
) {
|
||||
return $this->networkRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
||||
])));
|
||||
|
||||
return Cache::remember(
|
||||
$cacheKey,
|
||||
$this->cacheTime,
|
||||
fn() =>
|
||||
$this->networkRepository
|
||||
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->networkRepository->findBy($key, $value);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $withSum) {
|
||||
return $this->networkRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Network;
|
||||
|
||||
use App\Models\ModuleNetwork;
|
||||
use App\Repositories\BaseRepository;
|
||||
class NetworkRepository extends BaseRepository implements NetworkRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleNetwork::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
$query = $this->model->with($relationships)->select($select);
|
||||
|
||||
if (isset($data['status'])) {
|
||||
$query = $query->where("status", $data['status']);
|
||||
}
|
||||
if (isset($data['module_host_id']) && $data['module_host_id']) {
|
||||
$query->where("module_host_id", $data['module_host_id']);
|
||||
}
|
||||
if (count($withCount) > 0) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$model = $this->model;
|
||||
if (count($relationships) > 0) {
|
||||
foreach ($relationships as $relationship) {
|
||||
if (method_exists($model, $relationship)) {
|
||||
$model = $model->with($relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Xử lý withCount
|
||||
if (count($withCount) > 0) {
|
||||
foreach ($withCount as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withCount([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withCount($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Xử lý withSum
|
||||
if (count($withSum) > 0) {
|
||||
foreach ($withSum as $key => $items) {
|
||||
if (is_array($items)) {
|
||||
foreach ($items as $alias => $item) {
|
||||
$model = $model->withSum([
|
||||
$key . ' as ' . $alias => function ($query) use ($item) {
|
||||
$query->where($item['key'], $item['condition'], $item['value']);
|
||||
}
|
||||
], $item['sum']);
|
||||
}
|
||||
} else {
|
||||
$model = $model->withSum($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $model->find($id);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Network;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
interface NetworkRepositoryInterface extends BaseRepositoryInterface
|
||||
{
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
public function findBy(string $key = '', string|int|null $value = '');
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = []);
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
|
||||
class SnapshotCachedRepository extends BaseCachedRepository implements SnapshotRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public SnapshotRepository $snapshotRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->snapshotRepository->getModel();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
|
||||
class SnapshotLimitCachedRepository extends BaseCachedRepository implements SnapshotLimitRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public SnapshotLimitRepository $snapshotLimitRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->snapshotLimitRepository->getModel();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Models\ModuleSnapshotLimit;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class SnapshotLimitRepository extends BaseRepository implements SnapshotLimitRepositoryInterface {
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleSnapshotLimit::class;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface SnapshotLimitRepositoryInterface extends BaseRepositoryInterface {}
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Models\ModuleSnapshot;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class SnapshotRepository extends BaseRepository implements SnapshotRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return ModuleSnapshot::class;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\Snapshot;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface SnapshotRepositoryInterface extends BaseRepositoryInterface{}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\VirtualMachine;
|
||||
|
||||
use App\Models\VirtualMachines;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class VirtualMachineRepository extends BaseRepository implements VirtualMachineRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return VirtualMachines::class;
|
||||
}
|
||||
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
) {
|
||||
$query = $this->model
|
||||
->select($select)
|
||||
->with($relationships);
|
||||
|
||||
if (!empty($data['datacenter_id'])) {
|
||||
$query->where('datacenter_id', $data['datacenter_id']);
|
||||
}
|
||||
|
||||
if (!empty($data['host_id'])) {
|
||||
$query->where('host_id', $data['host_id']);
|
||||
}
|
||||
|
||||
if (!empty($data['name'])) {
|
||||
$query->where('name', 'like', '%' . $data['name'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($withCount)) {
|
||||
$query->withCount($withCount);
|
||||
}
|
||||
|
||||
if ($returnQuery) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
if (!empty($data['paginate']) || !empty($data['page'])) {
|
||||
return $query->paginate(
|
||||
$data['per_page'] ?? 15
|
||||
);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function findBy(string $key = '', string|int|null $value = '')
|
||||
{
|
||||
if (empty($key) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\VirtualMachine;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface VirtualMachineRepositoryInterface extends BaseRepositoryInterface {
|
||||
public function filter(
|
||||
array $data = [],
|
||||
array $relationships = [],
|
||||
array $withCount = [],
|
||||
array $select = ['*'],
|
||||
bool $returnQuery = false
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user