From 306e65e503436acdb7bde42b6542285da16f2e08 Mon Sep 17 00:00:00 2001 From: baodev0 Date: Sat, 25 Jul 2026 11:43:49 +0700 Subject: [PATCH] refactor: Replace cached repositories with direct repository implementations for Invoice and Order --- app/Providers/RepositoryProvider.php | 8 +- .../Invoice/InvoiceCachedRepository.php | 84 ------------------- .../Order/OrderCachedRepository.php | 65 -------------- 3 files changed, 4 insertions(+), 153 deletions(-) delete mode 100644 app/Repositories/Invoice/InvoiceCachedRepository.php delete mode 100644 app/Repositories/Order/OrderCachedRepository.php diff --git a/app/Providers/RepositoryProvider.php b/app/Providers/RepositoryProvider.php index 663f1a5..3f335bc 100644 --- a/app/Providers/RepositoryProvider.php +++ b/app/Providers/RepositoryProvider.php @@ -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 diff --git a/app/Repositories/Invoice/InvoiceCachedRepository.php b/app/Repositories/Invoice/InvoiceCachedRepository.php deleted file mode 100644 index ea525a6..0000000 --- a/app/Repositories/Invoice/InvoiceCachedRepository.php +++ /dev/null @@ -1,84 +0,0 @@ -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); - }); - } -} diff --git a/app/Repositories/Order/OrderCachedRepository.php b/app/Repositories/Order/OrderCachedRepository.php deleted file mode 100644 index 1c06638..0000000 --- a/app/Repositories/Order/OrderCachedRepository.php +++ /dev/null @@ -1,65 +0,0 @@ -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); - }); - } -}