From bf13686a8eeebf43d138452bd6b17c0f536230b8 Mon Sep 17 00:00:00 2001 From: Alexandre Batistella Bellas Date: Tue, 26 Dec 2023 16:15:51 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20mudar=20organiza=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20arquivos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/src/Entities/@shared/BaseEntity.php | 2 +- php/src/Entities/@shared/DTO/Body.php | 28 +++++++++++++ php/src/Entities/@shared/DTO/Headers.php | 28 +++++++++++++ ...RequestQueryParams.php => QueryParams.php} | 14 ++++++- php/src/Entities/@shared/DTO/RequestBody.php | 18 --------- .../Entities/@shared/DTO/RequestHeaders.php | 18 --------- .../Entities/@shared/DTO/RequestOptions.php | 14 +++---- .../Entities/@shared/DTO/ResponseOptions.php | 11 +++--- php/src/Entities/Borderos/Borderos.php | 39 +++++++++++++++++++ .../Schema/BorderoFindSuccessResponseBody.php | 13 +++++++ php/src/Repositories/BlingRepository.php | 24 ++++++------ 11 files changed, 146 insertions(+), 63 deletions(-) create mode 100644 php/src/Entities/@shared/DTO/Body.php create mode 100644 php/src/Entities/@shared/DTO/Headers.php rename php/src/Entities/@shared/DTO/{RequestQueryParams.php => QueryParams.php} (50%) delete mode 100644 php/src/Entities/@shared/DTO/RequestBody.php delete mode 100644 php/src/Entities/@shared/DTO/RequestHeaders.php create mode 100644 php/src/Entities/Borderos/Schema/BorderoFindSuccessResponseBody.php diff --git a/php/src/Entities/@shared/BaseEntity.php b/php/src/Entities/@shared/BaseEntity.php index 46fdc28..ff5a96b 100644 --- a/php/src/Entities/@shared/BaseEntity.php +++ b/php/src/Entities/@shared/BaseEntity.php @@ -14,7 +14,7 @@ abstract class BaseEntity * * @param IBlingRepository $repository Repositório para conexão com o Bling. */ - public function __construct(private IBlingRepository $repository) + public function __construct(protected IBlingRepository $repository) { } diff --git a/php/src/Entities/@shared/DTO/Body.php b/php/src/Entities/@shared/DTO/Body.php new file mode 100644 index 0000000..c274f92 --- /dev/null +++ b/php/src/Entities/@shared/DTO/Body.php @@ -0,0 +1,28 @@ + $content + */ + protected function __construct(protected array $content) + { + } + + /** + * Transforma o conteúdo em _array_. + * + * @return array + */ + public function toArray(): array + { + return isset($this->content) ? $this->content : []; + } +} diff --git a/php/src/Entities/@shared/DTO/Headers.php b/php/src/Entities/@shared/DTO/Headers.php new file mode 100644 index 0000000..bf63d38 --- /dev/null +++ b/php/src/Entities/@shared/DTO/Headers.php @@ -0,0 +1,28 @@ + $content + */ + protected function __construct(protected array $content) + { + } + + /** + * Transforma o conteúdo em _array_. + * + * @return array + */ + public function toArray(): array + { + return isset($this->content) ? $this->content : []; + } +} diff --git a/php/src/Entities/@shared/DTO/RequestQueryParams.php b/php/src/Entities/@shared/DTO/QueryParams.php similarity index 50% rename from php/src/Entities/@shared/DTO/RequestQueryParams.php rename to php/src/Entities/@shared/DTO/QueryParams.php index 68851e9..2c2d4d2 100644 --- a/php/src/Entities/@shared/DTO/RequestQueryParams.php +++ b/php/src/Entities/@shared/DTO/QueryParams.php @@ -5,14 +5,24 @@ /** * Parâmetros da requisição (para inserção como _query parameters_). */ -class RequestQueryParams +abstract class QueryParams { /** * Constrói o objeto. * * @param array $content */ - public function __construct(public array $content) + protected function __construct(protected array $content) { } + + /** + * Transforma o conteúdo em _array_. + * + * @return array + */ + public function toArray(): array + { + return isset($this->content) ? $this->content : []; + } } diff --git a/php/src/Entities/@shared/DTO/RequestBody.php b/php/src/Entities/@shared/DTO/RequestBody.php deleted file mode 100644 index 1e1c2da..0000000 --- a/php/src/Entities/@shared/DTO/RequestBody.php +++ /dev/null @@ -1,18 +0,0 @@ - $content - */ - public function __construct(public array $content) - { - } -} diff --git a/php/src/Entities/@shared/DTO/RequestOptions.php b/php/src/Entities/@shared/DTO/RequestOptions.php index 0fbff4c..5b839f6 100644 --- a/php/src/Entities/@shared/DTO/RequestOptions.php +++ b/php/src/Entities/@shared/DTO/RequestOptions.php @@ -3,7 +3,7 @@ namespace AleBatistella\BlingErpApi\Entities\Shared\DTO; /** - * Opções para envio de uma requisição. + * Dados para envio de uma requisição. */ class RequestOptions { @@ -11,15 +11,15 @@ class RequestOptions * Constrói o objeto. * * @param string $endpoint - * @param ?RequestQueryParams $queryParams - * @param ?RequestHeaders $headers - * @param ?RequestBody $body + * @param ?QueryParams $queryParams + * @param ?Headers $headers + * @param ?Body $body */ public function __construct( public string $endpoint, - public ?RequestQueryParams $queryParams, - public ?RequestHeaders $headers, - public ?RequestBody $body, + public ?QueryParams $queryParams = null, + public ?Headers $headers = null, + public ?Body $body = null, ) { } } diff --git a/php/src/Entities/@shared/DTO/ResponseOptions.php b/php/src/Entities/@shared/DTO/ResponseOptions.php index 9daeb7e..212b45c 100644 --- a/php/src/Entities/@shared/DTO/ResponseOptions.php +++ b/php/src/Entities/@shared/DTO/ResponseOptions.php @@ -3,19 +3,20 @@ namespace AleBatistella\BlingErpApi\Entities\Shared\DTO; /** - * Objeto representativo de todas os dados de resposta da requisição. + * Dados da resposta de uma requisição. */ class ResponseOptions { /** * Constrói o objeto. * - * @param ?RequestBody $body - * @param ?RequestHeaders $headers + * @param ?Body $body + * @param ?Headers $headers */ public function __construct( - public ?RequestBody $body = null, - public ?RequestHeaders $headers = [], + public int $status, + public ?Headers $headers = [], + public ?Body $body = null, ) { } } diff --git a/php/src/Entities/Borderos/Borderos.php b/php/src/Entities/Borderos/Borderos.php index f7d20b2..1efd365 100644 --- a/php/src/Entities/Borderos/Borderos.php +++ b/php/src/Entities/Borderos/Borderos.php @@ -3,7 +3,46 @@ namespace AleBatistella\BlingErpApi\Entities\Borderos; use AleBatistella\BlingErpApi\Entities\Shared\BaseEntity; +use AleBatistella\BlingErpApi\Entities\Shared\DTO\RequestOptions; +/** + * Entidade para interação com borderôs. + * + * @see https://developer.bling.com.br/referencia#/Border%C3%B4s + */ class Borderos extends BaseEntity { + /** + * Remove um borderô. + * + * @param int $idBordero ID para deleção. + * + * @return null Não há retorno. + * @throws {BlingApiException|BlingInternalException} + * + * @see https://developer.bling.com.br/referencia#/Border%C3%B4s/delete_borderos__idBordero_ + */ + public function delete(int $idBordero): null + { + return $this->repository->destroy(new RequestOptions( + endpoint: "borderos/$idBordero" + )); + } + + /** + * Encontra um borderô. + * + * @param params Parâmetros para a busca (somente o ID). + * + * @return {Promise} Os dados do borderô pesquisado. + * @throws {BlingApiException|BlingInternalException} + * + * @see https://developer.bling.com.br/referencia#/Border%C3%B4s/get_borderos__idBordero_ + */ + public function find(int $idBordero) + { + return $this->repository->show(new RequestOptions( + endpoint: "borderos/$idBordero" + )); + } } diff --git a/php/src/Entities/Borderos/Schema/BorderoFindSuccessResponseBody.php b/php/src/Entities/Borderos/Schema/BorderoFindSuccessResponseBody.php new file mode 100644 index 0000000..ed179cb --- /dev/null +++ b/php/src/Entities/Borderos/Schema/BorderoFindSuccessResponseBody.php @@ -0,0 +1,13 @@ +getBody()->getContents(); return new ResponseOptions( - body: new RequestBody(json_decode($rawResponseBody, true)), - headers: new RequestHeaders($response->getHeaders()) + body: new Body(json_decode($rawResponseBody, true)), + headers: new Headers($response->getHeaders()) ); } @@ -72,8 +72,8 @@ public function store(RequestOptions $options): ResponseOptions $rawResponseBody = $response->getBody()->getContents(); return new ResponseOptions( - body: new RequestBody(json_decode($rawResponseBody, true)), - headers: new RequestHeaders($response->getHeaders()) + body: new Body(json_decode($rawResponseBody, true)), + headers: new Headers($response->getHeaders()) ); } @@ -91,8 +91,8 @@ public function update(RequestOptions $options): ResponseOptions $rawResponseBody = $response->getBody()->getContents(); return new ResponseOptions( - body: new RequestBody(json_decode($rawResponseBody, true)), - headers: new RequestHeaders($response->getHeaders()) + body: new Body(json_decode($rawResponseBody, true)), + headers: new Headers($response->getHeaders()) ); } @@ -110,8 +110,8 @@ public function replace(RequestOptions $options): ResponseOptions $rawResponseBody = $response->getBody()->getContents(); return new ResponseOptions( - body: new RequestBody(json_decode($rawResponseBody, true)), - headers: new RequestHeaders($response->getHeaders()) + body: new Body(json_decode($rawResponseBody, true)), + headers: new Headers($response->getHeaders()) ); } @@ -129,8 +129,8 @@ public function destroy(RequestOptions $options): ResponseOptions $rawResponseBody = $response->getBody()->getContents(); return new ResponseOptions( - body: new RequestBody(json_decode($rawResponseBody, true)), - headers: new RequestHeaders($response->getHeaders()) + body: new Body(json_decode($rawResponseBody, true)), + headers: new Headers($response->getHeaders()) ); } }