From 1c2ad525437ba414e7c069bfa767e919bcccf38d Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 24 Jan 2024 22:07:53 +0300 Subject: [PATCH 1/2] Add interfaces for High performance api handles --- src/External/Api/TransactionQuery.php | 7 +--- src/External/Api/TransactionQueryHandler.php | 8 ++--- .../Api/TransactionQueryHandlerInterface.php | 2 +- .../Api/TransactionQueryInterface.php | 33 +++++++++++++++++++ src/External/Api/TransferQuery.php | 2 +- src/External/Api/TransferQueryHandler.php | 4 +-- .../Api/TransferQueryHandlerInterface.php | 2 +- src/External/Api/TransferQueryInterface.php | 22 +++++++++++++ 8 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 src/External/Api/TransactionQueryInterface.php create mode 100644 src/External/Api/TransferQueryInterface.php diff --git a/src/External/Api/TransactionQuery.php b/src/External/Api/TransactionQuery.php index 08659160b..39a1b36eb 100644 --- a/src/External/Api/TransactionQuery.php +++ b/src/External/Api/TransactionQuery.php @@ -5,14 +5,9 @@ namespace Bavix\Wallet\External\Api; use Bavix\Wallet\Interfaces\Wallet; -use Bavix\Wallet\Models\Transaction; -final readonly class TransactionQuery +final readonly class TransactionQuery implements TransactionQueryInterface { - public const TYPE_DEPOSIT = Transaction::TYPE_DEPOSIT; - - public const TYPE_WITHDRAW = Transaction::TYPE_WITHDRAW; - /** * @param self::TYPE_DEPOSIT|self::TYPE_WITHDRAW $type * @param array|null $meta diff --git a/src/External/Api/TransactionQueryHandler.php b/src/External/Api/TransactionQueryHandler.php index 5df4a661f..59c494a33 100644 --- a/src/External/Api/TransactionQueryHandler.php +++ b/src/External/Api/TransactionQueryHandler.php @@ -26,19 +26,19 @@ public function __construct( public function apply(array $objects): array { $wallets = $this->assistantService->getWallets( - array_map(static fn (TransactionQuery $query): Wallet => $query->getWallet(), $objects), + array_map(static fn (TransactionQueryInterface $query): Wallet => $query->getWallet(), $objects), ); $values = array_map( - fn (TransactionQuery $query) => match ($query->getType()) { - TransactionQuery::TYPE_DEPOSIT => $this->prepareService->deposit( + fn (TransactionQueryInterface $query) => match ($query->getType()) { + TransactionQueryInterface::TYPE_DEPOSIT => $this->prepareService->deposit( $query->getWallet(), $query->getAmount(), $query->getMeta(), $query->isConfirmed(), $query->getUuid(), ), - TransactionQuery::TYPE_WITHDRAW => $this->prepareService->withdraw( + TransactionQueryInterface::TYPE_WITHDRAW => $this->prepareService->withdraw( $query->getWallet(), $query->getAmount(), $query->getMeta(), diff --git a/src/External/Api/TransactionQueryHandlerInterface.php b/src/External/Api/TransactionQueryHandlerInterface.php index 5fead1dc8..7ba3ac0b3 100644 --- a/src/External/Api/TransactionQueryHandlerInterface.php +++ b/src/External/Api/TransactionQueryHandlerInterface.php @@ -17,7 +17,7 @@ interface TransactionQueryHandlerInterface * If there is a need to check the balance, then you need to wrap the method call in the AtomicServiceInterface * and check the correctness of the balance manually. * - * @param non-empty-array $objects + * @param non-empty-array $objects * * @return non-empty-array * diff --git a/src/External/Api/TransactionQueryInterface.php b/src/External/Api/TransactionQueryInterface.php new file mode 100644 index 000000000..d51dbdeb9 --- /dev/null +++ b/src/External/Api/TransactionQueryInterface.php @@ -0,0 +1,33 @@ +|null + */ + public function getMeta(): ?array; + + public function isConfirmed(): bool; + + public function getUuid(): ?string; +} diff --git a/src/External/Api/TransferQuery.php b/src/External/Api/TransferQuery.php index aeba1e501..76e0afe20 100644 --- a/src/External/Api/TransferQuery.php +++ b/src/External/Api/TransferQuery.php @@ -7,7 +7,7 @@ use Bavix\Wallet\External\Contracts\ExtraDtoInterface; use Bavix\Wallet\Interfaces\Wallet; -final readonly class TransferQuery +final readonly class TransferQuery implements TransferQueryInterface { /** * @param array|ExtraDtoInterface|null $meta diff --git a/src/External/Api/TransferQueryHandler.php b/src/External/Api/TransferQueryHandler.php index 51d72ea95..3f5a61457 100644 --- a/src/External/Api/TransferQueryHandler.php +++ b/src/External/Api/TransferQueryHandler.php @@ -27,11 +27,11 @@ public function __construct( public function apply(array $objects): array { $wallets = $this->assistantService->getWallets( - array_map(static fn (TransferQuery $query): Wallet => $query->getFrom(), $objects), + array_map(static fn (TransferQueryInterface $query): Wallet => $query->getFrom(), $objects), ); $values = array_map( - fn (TransferQuery $query) => $this->prepareService->transferLazy( + fn (TransferQueryInterface $query) => $this->prepareService->transferLazy( $query->getFrom(), $query->getTo(), Transfer::STATUS_TRANSFER, diff --git a/src/External/Api/TransferQueryHandlerInterface.php b/src/External/Api/TransferQueryHandlerInterface.php index f489a510c..095c4c78f 100644 --- a/src/External/Api/TransferQueryHandlerInterface.php +++ b/src/External/Api/TransferQueryHandlerInterface.php @@ -17,7 +17,7 @@ interface TransferQueryHandlerInterface * If there is a need to check the balance, then you need to wrap the method call in the AtomicServiceInterface * and check the correctness of the balance manually. * - * @param non-empty-array $objects + * @param non-empty-array $objects * * @return non-empty-array * diff --git a/src/External/Api/TransferQueryInterface.php b/src/External/Api/TransferQueryInterface.php new file mode 100644 index 000000000..03bae4ebf --- /dev/null +++ b/src/External/Api/TransferQueryInterface.php @@ -0,0 +1,22 @@ +|ExtraDtoInterface|null + */ + public function getMeta(): array|ExtraDtoInterface|null; +} From ec1ba2cbbe2973b60b18b91b801ecd87b6bd7f3c Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 24 Jan 2024 22:19:25 +0300 Subject: [PATCH 2/2] fix deptrac.yaml --- deptrac.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deptrac.yaml b/deptrac.yaml index 10c17c18c..6b2191a41 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -171,12 +171,13 @@ parameters: - Model ApiQuery: + - Api - Model - Contract Api: - Model - - ApiQuery + - Contract - InternalException ApiHandler: