refactor: Replace cached repositories with direct repository implementations for Invoice and Order
This commit is contained in:
@@ -24,7 +24,7 @@ use App\Repositories\Group\GroupCachedRepository;
|
||||
use App\Repositories\Group\GroupRepositoryInterface;
|
||||
use App\Repositories\Hosting\HostingCachedRepository;
|
||||
use App\Repositories\Hosting\HostingRepositoryInterface;
|
||||
use App\Repositories\Invoice\InvoiceCachedRepository;
|
||||
use App\Repositories\Invoice\InvoiceRepository;
|
||||
use App\Repositories\Invoice\InvoiceRepositoryInterface;
|
||||
use App\Repositories\InvoiceAttachment\InvoiceAttachmentRepository;
|
||||
use App\Repositories\InvoiceAttachment\InvoiceAttachmentRepositoryInterface;
|
||||
@@ -46,7 +46,7 @@ use App\Repositories\Module\IPPool\IPPoolCachedRepository;
|
||||
use App\Repositories\Module\IPPool\IPPoolRepositoryInterface;
|
||||
use App\Repositories\Note\NoteCachedRepository;
|
||||
use App\Repositories\Note\NoteRepositoryInterface;
|
||||
use App\Repositories\Order\OrderCachedRepository;
|
||||
use App\Repositories\Order\OrderRepository;
|
||||
use App\Repositories\Order\OrderRepositoryInterface;
|
||||
use App\Repositories\Os\OsCachedRepository;
|
||||
use App\Repositories\Os\OsRepositoryInterface;
|
||||
@@ -143,7 +143,7 @@ class RepositoryProvider extends ServiceProvider
|
||||
//Hosting
|
||||
$this->app->singleton(HostingRepositoryInterface::class, HostingCachedRepository::class);
|
||||
//Invoice
|
||||
$this->app->singleton(InvoiceRepositoryInterface::class, InvoiceCachedRepository::class);
|
||||
$this->app->singleton(InvoiceRepositoryInterface::class, InvoiceRepository::class);
|
||||
//Invoice Attachment
|
||||
$this->app->singleton(InvoiceAttachmentRepositoryInterface::class, InvoiceAttachmentRepository::class);
|
||||
//Invoice Item
|
||||
@@ -157,7 +157,7 @@ class RepositoryProvider extends ServiceProvider
|
||||
//Note
|
||||
$this->app->singleton(NoteRepositoryInterface::class, NoteCachedRepository::class);
|
||||
//Order
|
||||
$this->app->singleton(OrderRepositoryInterface::class, OrderCachedRepository::class);
|
||||
$this->app->singleton(OrderRepositoryInterface::class, OrderRepository::class);
|
||||
//Os
|
||||
$this->app->singleton(OsRepositoryInterface::class, OsCachedRepository::class);
|
||||
// Os Group
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Invoice;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class InvoiceCachedRepository extends BaseCachedRepository implements InvoiceRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public InvoiceRepository $invoiceRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->invoiceRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
if ($returnQuery) {
|
||||
return $this->invoiceRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
||||
}
|
||||
|
||||
$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->invoiceRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
public function get_billing_year(int $year = 0)
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'get_billing_year' => [
|
||||
'year' => $year
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($year) {
|
||||
return $this->invoiceRepository->get_billing_year($year);
|
||||
});
|
||||
}
|
||||
public function get_billing_month(int $month = 0)
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'get_billing_month' => [
|
||||
'month' => $month
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($month) {
|
||||
return $this->invoiceRepository->get_billing_month($month);
|
||||
});
|
||||
}
|
||||
public function get_billing_day(int|string $day = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'get_billing_day' => [
|
||||
'day' => $day
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($day) {
|
||||
return $this->invoiceRepository->get_billing_day($day);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(string $ordernum = '', array $relationships = [], array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'ordernum' => $ordernum,
|
||||
'relationships' => $relationships,
|
||||
'withCount' => $withCount,
|
||||
'withSum' => $withSum
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($ordernum, $relationships, $withCount, $withSum) {
|
||||
return $this->invoiceRepository->findWithRelationships($ordernum, $relationships, $withCount, $withSum);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Order;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class OrderCachedRepository extends BaseCachedRepository implements OrderRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public OrderRepository $orderRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->orderRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
||||
{
|
||||
if ($returnQuery) {
|
||||
return $this->orderRepository->filter($data, $relationships, $withCount, $select, true);
|
||||
}
|
||||
|
||||
$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->orderRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships,
|
||||
'withCount' => $withCount,
|
||||
'withSum' => $withSum
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
||||
return $this->orderRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
||||
});
|
||||
}
|
||||
public function updateBy(string $key = '', string|int $value = '', array $data = [])
|
||||
{
|
||||
$this->orderRepository->updateBy($key, $value,$data);
|
||||
$this->clearCache();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function findByOrderNum(string $orderNum)
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode(['findByOrderNum' => $orderNum])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($orderNum) {
|
||||
return $this->orderRepository->findByOrderNum($orderNum);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user