51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\GraphQLBundle\ApiAdmin\Controller;
|
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\Collection\SaleCollection;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\Parameters;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\Sale\Input\SaleFilterInput;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Types\Sale\Sale;
|
|
use KupShop\GraphQLBundle\ApiAdmin\Util\SaleUtil;
|
|
use TheCodingMachine\GraphQLite\Annotations\Query;
|
|
use TheCodingMachine\GraphQLite\Annotations\UseInputType;
|
|
|
|
class SaleController
|
|
{
|
|
public function __construct(
|
|
private readonly ?SaleUtil $saleUtil,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Vrací prodejku podle ID.
|
|
*/
|
|
#[Query]
|
|
#[Module(\Modules::SALES)]
|
|
public function sale(int $id): ?Sale
|
|
{
|
|
return $this->saleUtil->getSale($id);
|
|
}
|
|
|
|
/**
|
|
* Vrací seznam prodejek.
|
|
*/
|
|
#[Query]
|
|
#[Module(\Modules::SALES)]
|
|
public function sales(
|
|
ResolveInfo $resolveInfo,
|
|
int $offset = 0,
|
|
int $limit = 100,
|
|
#[UseInputType('SaleSortInput')] ?Parameters $sort = null,
|
|
?SaleFilterInput $filter = null,
|
|
): SaleCollection {
|
|
$fetchItems = $resolveInfo->getFieldSelection(1)['items']['items'] ?? false;
|
|
|
|
return $this->saleUtil->getSales($offset, $limit, $sort, $filter, $fetchItems);
|
|
}
|
|
}
|