diff --git a/src/ApiPlatform/Resources/CreditSlip/CreditSlipIdsByDateRange.php b/src/ApiPlatform/Resources/CreditSlip/CreditSlipIdsByDateRange.php new file mode 100644 index 00000000..24cbf010 --- /dev/null +++ b/src/ApiPlatform/Resources/CreditSlip/CreditSlipIdsByDateRange.php @@ -0,0 +1,86 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\CreditSlip; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\CreditSlip\Query\GetCreditSlipIdsByDateRange; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection; +use PrestaShop\PrestaShop\Core\Domain\CreditSlip\Exception\CreditSlipException; +use PrestaShop\PrestaShop\Core\Domain\CreditSlip\Exception\CreditSlipNotFoundException; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSGetCollection( + uriTemplate: '/credit-slip/{dateFrom}/{dateTo}', + openapiContext: [ + 'parameters' => [ + [ + 'name' => 'dateFrom', + 'in' => 'path', + 'required' => true, + 'schema' => [ + 'type' => 'string', + 'format' => 'date', + ], + ], + [ + 'name' => 'dateTo', + 'in' => 'path', + 'required' => true, + 'schema' => [ + 'type' => 'string', + 'format' => 'date', + ], + ], + ], + ], + CQRSQuery: GetCreditSlipIdsByDateRange::class, + CQRSQueryMapping: self::QUERY_MAPPING, + scopes: ['slip_read'], + ), + ], + exceptionToStatus: [ + CreditSlipConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CreditSlipNotFoundException::class => Response::HTTP_NOT_FOUND, + CreditSlipException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class CreditSlip +{ + #[Assert\NotBlank] + #[Assert\Date] + public ?string $dateFrom = null; + + #[Assert\NotBlank] + #[Assert\Date] + public ?string $dateTo = null; + + public const QUERY_MAPPING = [ + '[dateFrom]' => '[dateTimeFrom]', + '[dateTo]' => '[dateTimeTo]', + ]; +}