add repository for quickbooks data

This commit is contained in:
karneaud 2024-07-29 16:16:48 -04:00
parent ee334fd974
commit 4c3829b8c1
3 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace App\Repositories\Import\Quickbooks\Contracts;
use Illuminate\Support\Collection;
interface RepositoryInterface {
function get(int $max = 100): Collection;
function all(): Collection;
function count(): int;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Repositories\Import\QuickBooks;
use App\Repositories\Import\Quickbooks\Repository;
use App\Repositories\Import\Quickbooks\Contracts\RepositoryInterface;
class CustomerRepository extends Repository implements RepositoryInterface
{
protected string $entity = "Customer";
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\Repositories\Import\QuickBooks;
use Illuminate\Support\Collection;
use App\Repositories\Import\Quickbooks\Contracts\RepositoryInterface;
use App\Services\Import\Quickbooks\Contracts\SdkInterface as QuickbooksInterface;
use App\Repositories\Import\Quickbooks\Transformers\Transformer as QuickbooksTransformer;
abstract class Repository implements RepositoryInterface
{
protected string $entity;
protected QuickbooksInterface $db;
protected QuickbooksTransformer $transfomer;
public function __construct(QuickbooksInterface $db, QuickbooksTransformer $transfomer)
{
$this->db= $db;
$this->transformer = $transfomer;
}
public function count() : int {
return $this->db->totalRecords($this->entity);
}
public function all() : Collection
{
return $this->get($this->count());
}
public function get(int $max = 100): Collection
{
return $this->transformer->transform($this->db->fetchRecords($this->entity, $max), $this->entity);
}
}