mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Merge branch '1.13' into 1.14
* 1.13: [Admin] Pass admin path name parameter to AdminUriBasedSectionResolver Update docs/customization/api/adding_and_removing_endpoints.rst Apply suggestions from code review [API] Refactor statistics constraints doc: Adding a tip about api's preventing methods beside GET to load non cart orders by default
This commit is contained in:
commit
d4531ff063
4 changed files with 43 additions and 16 deletions
|
|
@ -23,6 +23,16 @@ And that's all, now you have a new endpoint with your custom logic.
|
|||
|
||||
Read more about API Platform endpoint configuration `here <https://api-platform.com/docs/core/operations/>`_
|
||||
|
||||
Good to Know
|
||||
~~~~~~~~~~~~
|
||||
|
||||
.. tip::
|
||||
API Platform is configured to prevent modifications to orders not in the ``cart`` state. There are only a few
|
||||
specific actions allowed. This is done by preventing orders not in the state ``cart`` from loading if the method
|
||||
is not ``GET``. So if you need to add an endpoint to an API that needs to edit orders that are not in the state
|
||||
``cart``, you will need to whitelist this endpoint. This can be done by adding your API route to the
|
||||
``sylius.api.doctrine_extension.order_shop_user_item.filter_cart.allowed_non_get_operations`` parameter.
|
||||
|
||||
How to remove an endpoint?
|
||||
--------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
<service id="sylius_admin.context.locale.admin_based" alias="sylius.context.locale.admin_based" />
|
||||
|
||||
<service id="sylius.section_resolver.admin_uri_based_section_resolver" class="Sylius\Bundle\AdminBundle\SectionResolver\AdminUriBasedSectionResolver">
|
||||
<argument>/admin</argument>
|
||||
<argument>/%sylius_admin.path_name%</argument>
|
||||
<tag name="sylius.uri_based_section_resolver" priority="20" />
|
||||
</service>
|
||||
<service id="sylius_admin.section_resolver.admin_uri_based" alias="sylius.section_resolver.admin_uri_based_section_resolver" />
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Sylius\Bundle\ApiBundle\Controller;
|
|||
|
||||
use ApiPlatform\Symfony\Validator\Exception\ValidationException;
|
||||
use Sylius\Bundle\ApiBundle\Query\GetStatistics;
|
||||
use Sylius\Bundle\ApiBundle\Validator\Constraints;
|
||||
use Sylius\Bundle\ApiBundle\Validator\Constraints\Code;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
@ -25,6 +25,7 @@ use Symfony\Component\Messenger\MessageBusInterface;
|
|||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints as SymfonyConstraints;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
final class GetStatisticsAction
|
||||
|
|
@ -90,9 +91,8 @@ final class GetStatisticsAction
|
|||
private function createInputDataConstraints(): array
|
||||
{
|
||||
return [
|
||||
new SymfonyConstraints\Sequentially([
|
||||
new SymfonyConstraints\Collection([
|
||||
'channelCode' => new Constraints\Code(),
|
||||
'channelCode' => new Code(),
|
||||
'startDate' => [
|
||||
new SymfonyConstraints\NotBlank(),
|
||||
new SymfonyConstraints\DateTime('Y-m-d\TH:i:s', message: 'sylius.date_time.invalid'),
|
||||
|
|
@ -103,11 +103,20 @@ final class GetStatisticsAction
|
|||
new SymfonyConstraints\DateTime('Y-m-d\TH:i:s', message: 'sylius.date_time.invalid'),
|
||||
],
|
||||
]),
|
||||
new SymfonyConstraints\Expression(expression: 'value["startDate"] < value["endDate"]', message: 'sylius.statistics.end_date.invalid'),
|
||||
]),
|
||||
new SymfonyConstraints\Callback(function (array $data, ExecutionContextInterface $context) {
|
||||
$this->validateDateRange($data, $context);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/** @param array<array-key, mixed> $data */
|
||||
private function validateDateRange(array $data, ExecutionContextInterface $context): void
|
||||
{
|
||||
if (isset($data['startDate'], $data['endDate']) && $data['startDate'] >= $data['endDate']) {
|
||||
$context->buildViolation('sylius.statistics.end_date.invalid')->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, array{interval: string, period_format: string}> $intervalsMap
|
||||
*
|
||||
|
|
|
|||
|
|
@ -347,6 +347,10 @@ final class StatisticsTest extends JsonApiTestCase
|
|||
'propertyPath' => '[endDate]',
|
||||
'message' => 'This value should not be blank.',
|
||||
],
|
||||
[
|
||||
'propertyPath' => '',
|
||||
'message' => 'The start date must be earlier than the end date.',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
@ -380,6 +384,10 @@ final class StatisticsTest extends JsonApiTestCase
|
|||
'propertyPath' => '[startDate]',
|
||||
'message' => 'The date time is not valid ISO 8601 date time in Y-m-d\TH:i:s format.',
|
||||
],
|
||||
[
|
||||
'propertyPath' => '',
|
||||
'message' => 'The start date must be earlier than the end date.',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue