-
unknown authored363decac
<?php
namespace App\Entities\Company\Implementations;
use App\Entities\Api\Repositories\ApiRepository;
use App\Entities\Company\Repositories\CompanyRepositoryInterface;
class CompanyRepository extends ApiRepository implements CompanyRepositoryInterface
{
const ENDPOINT = '/v1/companies';
/**
* @throws \App\Entities\Api\Exceptions\ApiException
*/
public function get(): array
{
$this->response = $this->httpClient->get(self::ENDPOINT);
$this->validateResponse();
return $this->response['companies'];
}
/**
* @throws \App\Entities\Api\Exceptions\ApiException
*/
public function create(array $data): array
{
$this->response = $this->httpClient->post(self::ENDPOINT, $data);
$this->validateResponse();
return $this->response['company'];
}
/**
* @throws \App\Entities\Api\Exceptions\ApiException
*/
public function update(int|string $id, array $data): array
{
$this->response = $this->httpClient->put(self::ENDPOINT . "/$id", $data);
$this->validateResponse();
return $this->response['company'];
}
/**
* @throws \App\Entities\Api\Exceptions\ApiException
*/
public function delete(int|string $id): array
{
$this->response = $this->httpClient->delete(self::ENDPOINT . "/$id");
$this->validateResponse();
return $this->response['company'];
}
}