From bc7fcbf881807e858466fb4e4776a879bab6ad5c Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 26 Oct 2023 12:11:09 +0200 Subject: [PATCH] extract endpoints for capacity Create/Upsert/ListPerPage --- src/Capacity/Create.php | 45 +++++++++++++++++- src/Capacity/ListPerPage.php | 92 ++++++++++++++++++++++++++++++++++-- src/Capacity/Upsert.php | 35 +++++++++++++- 3 files changed, 164 insertions(+), 8 deletions(-) diff --git a/src/Capacity/Create.php b/src/Capacity/Create.php index 0b02a08..cc4d452 100644 --- a/src/Capacity/Create.php +++ b/src/Capacity/Create.php @@ -10,7 +10,7 @@ final class Create implements CapacityInterface { - private static array $endpoints = [ + private static array $endpointsLegacy = [ // Core Endpoints 'channels', 'countries', @@ -40,10 +40,51 @@ final class Create implements CapacityInterface 'zones', ]; + private static array $endpointsAdmin = [ + // Core Endpoints + 'administrator', + 'avatarImage', + 'catalogPromotion', + 'channel', + 'country', + 'currency', + 'customerGroup', + 'exchangeRate', + 'locale', + 'product', + 'productAssociationType', + 'productOption', + 'productVariant', + 'promotion', + 'resetPasswordRequest', + 'shippingCategory', + 'shippingMethod', + 'taxCategory', + 'taxon', + 'verifyCustomerAccount', + 'zone', + ]; + + private static array $endpointsShop = [ + // Core Endpoints + 'address', + 'customer', + 'order', + 'orderItem', + 'productReview', + 'resetPasswordRequest', + 'verifyCustomerAccount', + ]; + public function applies(array $config): bool { + $endpoints = match($config['api_type']) { + 'admin' => self::$endpointsAdmin, + 'shop' =>self::$endpointsShop, + 'legacy' => self::$endpointsLegacy, + }; return isset($config['type']) - && \in_array($config['type'], self::$endpoints) + && \in_array($config['type'], $endpoints) && isset($config['method']) && 'create' === $config['method']; } diff --git a/src/Capacity/ListPerPage.php b/src/Capacity/ListPerPage.php index fef12ef..b78d9b9 100644 --- a/src/Capacity/ListPerPage.php +++ b/src/Capacity/ListPerPage.php @@ -13,7 +13,7 @@ final class ListPerPage implements CapacityInterface { - private static array $endpoints = [ + private static array $endpointsLegacy = [ // Simple resources Endpoints 'channels', 'countries', @@ -41,12 +41,78 @@ final class ListPerPage implements CapacityInterface 'zones', ]; - private static array $doubleEndpoints = [ + private static array $endpointsAdmin = [ + // Simple Ressource Endpoints + 'adjustment', + 'administrator', + 'catalogPromotion', + 'channel', + 'country', + 'currency', + 'customerGroup', + 'exchangeRate', + 'locale', + 'order', + 'payment', + 'product', + 'productAssociationType', + 'productImage', + 'productOption', + 'productOptionValue', + 'productReview', + 'productTaxon', + 'productVariant', + 'promotion', + 'province', + 'shipment', + 'shippingCategory', + 'shippingMethod', + 'ShopBillingData', + 'taxCategory', + 'taxon', + 'taxonTranslation', + 'zone', + 'zoneMember', + ]; + + private static array $endpointsShop = [ + // Simple Ressource Endpoints + 'address', + 'adjustment', + 'country', + 'currency', + 'locale', + 'order', + 'orderItem', + 'payment', + 'paymentMethod', + 'product', + 'productReview', + 'productVariant', + 'shipment', + 'shippingMethod', + 'taxon', + ]; + + private static array $doubleEndpointsLegacy = [ // Double resources Endpoints 'productReviews', 'productVariants', 'promotionCoupons', ]; + private static array $doubleEndpointsAdmin = [ + // Double resources Endpoints + 'adjustment', + 'province', + 'shopBillingData', + 'zoneMember', + ]; + + private static array $doubleEndpointsShop = [ + // Double resources Endpoints + 'adjustment', + 'order', + ]; public function __construct(private readonly ExpressionLanguage $interpreter) { @@ -54,13 +120,31 @@ public function __construct(private readonly ExpressionLanguage $interpreter) public function applies(array $config): bool { + switch($config['api_type']) { + case 'admin': + $endpoints = self::$endpointsAdmin; + $doubleEndpoints = self::$doubleEndpointsAdmin; + break; + case 'shop': + $endpoints = self::$endpointsShop; + $doubleEndpoints = self::$doubleEndpointsShop; + break; + case 'legacy': + $endpoints = self::$endpointsLegacy; + $doubleEndpoints = self::$doubleEndpointsLegacy; + break; + default: + $endpoints = []; + $doubleEndpoints = []; + break; + } return isset($config['type']) - && (\in_array($config['type'], self::$endpoints) || \in_array($config['type'], self::$doubleEndpoints)) + && (\in_array($config['type'], $endpoints) || \in_array($config['type'], $doubleEndpoints)) && isset($config['method']) && 'listPerPage' === $config['method']; } - private function compileFilters(array ...$filters): Node + private function compileFilters(array ...$filters): Node\Expr { $builder = new Sylius\Builder\Search(); foreach ($filters as $filter) { diff --git a/src/Capacity/Upsert.php b/src/Capacity/Upsert.php index 83b7079..92eb190 100644 --- a/src/Capacity/Upsert.php +++ b/src/Capacity/Upsert.php @@ -10,7 +10,7 @@ final class Upsert implements CapacityInterface { - private static array $endpoints = [ + private static array $endpointsLegacy = [ // Core Endpoints 'carts', 'channels', @@ -42,10 +42,41 @@ final class Upsert implements CapacityInterface 'zones', ]; + private static array $endpointsAdmin = [ + // Core Endpoints + 'administrator', + 'catalogPromotion', + 'customerGroup', + 'exchangeRate', + 'product', + 'productAssociationType', + 'productOption', + 'productReview', + 'productVariant', + 'province', + 'shippingCategory', + 'shippingMethod', + 'taxCategory', + 'taxon', + 'zone', + ]; + + private static array $endpointsShop = [ + // Core Endpoints + 'address', + 'customer', + 'order', + ]; + public function applies(array $config): bool { + $endpoints = match($config['api_type']) { + 'admin' => self::$endpointsAdmin, + 'shop' =>self::$endpointsShop, + 'legacy' => self::$endpointsLegacy, + }; return isset($config['type']) - && \in_array($config['type'], self::$endpoints) + && \in_array($config['type'], $endpoints) && isset($config['method']) && 'upsert' === $config['method']; }