Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID指定でproduct/order/customerを取得するQueryを追加 #48

Merged
merged 3 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions DependencyInjection/Compiler/ApiCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use League\OAuth2\Server\CryptKey;
use Plugin\Api\GraphQL\AllowList;
use Plugin\Api\GraphQL\Query;
use Plugin\Api\GraphQL\Types;
use Plugin\Api\Service\WebHookEvents;
use Plugin\Api\Service\WebHookTrigger;
Expand All @@ -29,6 +30,7 @@ public function process(ContainerBuilder $container)
$this->configureTrigger($container);
$this->configureAllowList($container);
$this->configureKeyPair($container);
$this->configureQuery($container);

$plugins = $container->getParameter('eccube.plugins.enabled');
if (!in_array('Api', $plugins)) {
Expand All @@ -39,6 +41,16 @@ public function process(ContainerBuilder $container)
}
}

private function configureQuery(ContainerBuilder $container)
{
$serviceDef = $container->getDefinition('api.queries');
foreach ($container->getDefinitions() as $definition) {
if (is_subclass_of($definition->getClass(), Query::class)) {
$serviceDef->addMethodCall('append', [$definition]);
}
}
}

private function configureTrigger(ContainerBuilder $container)
{
$serviceDef = $container->getDefinition(WebHookEvents::class);
Expand Down
27 changes: 27 additions & 0 deletions GraphQL/Query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL;

interface Query
{
/**
* @return string
*/
public function getName();

/**
* @return array
*/
public function getQuery();
}
32 changes: 32 additions & 0 deletions GraphQL/Query/CustomerQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Customer;

class CustomerQuery extends SingleResultQuery
{
/**
* CustomerQuery constructor.
*/
public function __construct()
{
parent::__construct(Customer::class);
}

public function getName()
{
return 'customer';
}
}
47 changes: 47 additions & 0 deletions GraphQL/Query/CustomersQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Customer;
use Eccube\Form\Type\Admin\SearchCustomerType;
use Eccube\Repository\CustomerRepository;

class CustomersQuery extends SearchFormQuery
{
/**
* @var CustomerRepository
*/
private $customerRepository;

/**
* CustomersQuery constructor.
* @param CustomerRepository $customerRepository
*/
public function __construct(CustomerRepository $customerRepository)
{
$this->customerRepository = $customerRepository;
}

public function getName()
{
return 'customers';
}

public function getQuery()
{
return $this->createQuery(Customer::class, SearchCustomerType::class, function ($searchData) {
return $this->customerRepository->getQueryBuilderBySearchData($searchData);
});
}
}
32 changes: 32 additions & 0 deletions GraphQL/Query/OrderQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Order;

class OrderQuery extends SingleResultQuery
{
/**
* OrderQuery constructor.
*/
public function __construct()
{
parent::__construct(Order::class);
}

public function getName()
{
return 'order';
}
}
48 changes: 48 additions & 0 deletions GraphQL/Query/OrdersQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Order;
use Eccube\Form\Type\Admin\SearchOrderType;
use Eccube\Repository\OrderRepository;

class OrdersQuery extends SearchFormQuery
{
/**
* @var OrderRepository
*/
private $orderRepository;

/**
* OrdersQuery constructor.
*
* @param $orderRepository
*/
public function __construct(OrderRepository $orderRepository)
{
$this->orderRepository = $orderRepository;
}

public function getName()
{
return 'orders';
}

public function getQuery()
{
return $this->createQuery(Order::class, SearchOrderType::class, function ($searchData) {
return $this->orderRepository->getQueryBuilderBySearchDataForAdmin($searchData);
});
}
}
32 changes: 32 additions & 0 deletions GraphQL/Query/ProductQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Product;

class ProductQuery extends SingleResultQuery
{
/**
* ProductQuery constructor.
*/
public function __construct()
{
parent::__construct(Product::class);
}

public function getName()
{
return 'product';
}
}
48 changes: 48 additions & 0 deletions GraphQL/Query/ProductsQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Api\GraphQL\Query;

use Eccube\Entity\Product;
use Eccube\Form\Type\Admin\SearchProductType;
use Eccube\Repository\ProductRepository;

class ProductsQuery extends SearchFormQuery
{
/**
* @var ProductRepository
*/
private $productRepository;

/**
* ProductQuery constructor.
*
* @param $productRepository
*/
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}

public function getName()
{
return 'products';
}

public function getQuery()
{
return $this->createQuery(Product::class, SearchProductType::class, function ($searchData) {
return $this->productRepository->getQueryBuilderBySearchDataForAdmin($searchData);
});
}
}