[API][Address] Upgrade Address resource

This commit is contained in:
Wojdylak 2024-05-09 21:01:52 +02:00
parent c9339d249f
commit 0f51146baf
No known key found for this signature in database
GPG key ID: 7509E560A6821ABE
9 changed files with 181 additions and 263 deletions

View file

@ -30,7 +30,7 @@
"ext-intl": "*",
"ext-json": "*",
"ext-simplexml": "*",
"api-platform/core": "^3.2.2",
"api-platform/core": "~3.2.2",
"babdev/pagerfanta-bundle": "^3.0",
"behat/transliterator": "^1.3",
"doctrine/collections": "^1.6",

View file

@ -595,41 +595,6 @@ parameters:
count: 1
path: src/Sylius/Bundle/ApiBundle/Converter/IriToIdentifierConverterInterface.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:persist\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:persist\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has no return type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:supports\\(\\) has parameter \\$data with no type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AdminUserDataPersister\\:\\:persist\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
@ -1505,11 +1470,6 @@ parameters:
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryCollectionExtension/AcceptedProductReviewsExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryCollectionExtension\\\\AddressesExtension\\:\\:applyToCollection\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryCollectionExtension/AddressesExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryCollectionExtension\\\\AvailableProductAssociationsInProductCollectionExtension\\:\\:applyToCollection\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
@ -1600,21 +1560,6 @@ parameters:
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryExtension/ExchangeRateExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has no return type specified\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has parameter \\$identifiers with no value type specified in iterable type array\\.$#"
count: 1
path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php
-
message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\EnabledProductInProductAssociationItemExtension\\:\\:applyToItem\\(\\) has no return type specified\\.$#"
count: 1

View file

@ -15,7 +15,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0 https://api-platform.com/schema/metadata/properties-3.0.xsd"
>
<property resource="Sylius\Component\Core\Model\Address" name="id" identifier="true" writable="false" genId="false"/>
<property resource="Sylius\Component\Core\Model\Address" name="id" identifier="true" writable="false"/>
<property resource="Sylius\Component\Core\Model\Address" name="firstName" writable="true" />
<property resource="Sylius\Component\Core\Model\Address" name="lastName" writable="true" />
<property resource="Sylius\Component\Core\Model\Address" name="city" writable="true" />

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<properties xmlns="https://api-platform.com/schema/metadata/properties-3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0 https://api-platform.com/schema/metadata/properties-3.0.xsd"
>
<property resource="Sylius\Component\Addressing\Model\AddressLogEntry" name="id" identifier="true" writable="false"/>
</properties>

View file

@ -28,9 +28,43 @@
</validationContext>
<operations>
<operation class="ApiPlatform\Metadata\Get" uriTemplate="/admin/addresses/{id}">
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:show</value>
</values>
</value>
</values>
</normalizationContext>
</operation>
<operation class="ApiPlatform\Metadata\Put" uriTemplate="/admin/addresses/{id}">
<denormalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:update</value>
</values>
</value>
</values>
</denormalizationContext>
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:show</value>
</values>
</value>
</values>
</normalizationContext>
</operation>
<operation
class="ApiPlatform\Metadata\Get"
uriTemplate="shop/addresses/{id}"
uriTemplate="/shop/addresses/{id}"
security="is_granted('SYLIUS_CUSTOMER')"
>
<normalizationContext>
<values>
@ -45,7 +79,8 @@
<operation
class="ApiPlatform\Metadata\GetCollection"
uriTemplate="shop/addresses"
uriTemplate="/shop/addresses"
security="is_granted('SYLIUS_CUSTOMER')"
>
<normalizationContext>
<values>
@ -59,12 +94,11 @@
</operation>
<operation
class="ApiPlatform\Metadata\Delete"
uriTemplate="shop/addresses/{id}"
/>
<operation class="ApiPlatform\Metadata\Post"
uriTemplate="shop/addresses"
class="ApiPlatform\Metadata\Post"
uriTemplate="/shop/addresses"
security="is_granted('SYLIUS_CUSTOMER')"
itemUriTemplate="/shop/addresses/{id}"
processor="sylius.api.state_processor.post.address"
>
<denormalizationContext>
<values>
@ -88,7 +122,8 @@
<operation
class="ApiPlatform\Metadata\Put"
uriTemplate="shop/addresses"
uriTemplate="/shop/addresses/{id}"
security="is_granted('SYLIUS_CUSTOMER')"
>
<denormalizationContext>
<values>
@ -111,67 +146,10 @@
</operation>
<operation
class="ApiPlatform\Metadata\Get"
uriTemplate="admin/addresses/{id}"
>
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:show</value>
</values>
</value>
</values>
</normalizationContext>
</operation>
<operation
class="ApiPlatform\Metadata\Get"
uriTemplate="admin/addresses/{id}/log-entries"
controller="Sylius\Bundle\ApiBundle\Controller\GetAddressLogEntryCollectionAction"
deserialize="false"
>
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:log_entry:show</value>
</values>
</value>
</values>
</normalizationContext>
<openapiContext>
<values>
<value name="summary">Get address log entries</value>
<value name="description">Get address log entries</value>
</values>
</openapiContext>
</operation>
<operation
class="ApiPlatform\Metadata\Put"
uriTemplate="admin/addresses/{id}"
>
<denormalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:update</value>
</values>
</value>
</values>
</denormalizationContext>
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:show</value>
</values>
</value>
</values>
</normalizationContext>
</operation>
class="ApiPlatform\Metadata\Delete"
uriTemplate="/shop/addresses/{id}"
security="is_granted('SYLIUS_CUSTOMER')"
/>
</operations>
</resource>
</resources>

View file

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources
xmlns="https://api-platform.com/schema/metadata/resources-3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0 https://api-platform.com/schema/metadata/resources-3.0.xsd"
>
<resource class="Sylius\Component\Addressing\Model\AddressLogEntry" shortName="AddressLogEntry">
<operations>
<operation
class="ApiPlatform\Metadata\Get"
controller="ApiPlatform\Action\NotFoundAction"
read="false"
output="false"
routePrefix="admin"
/>
</operations>
</resource>
<resource class="Sylius\Component\Addressing\Model\AddressLogEntry" uriTemplate="/admin/addresses/{id}/log-entries">
<uriVariables>
<uriVariable parameterName="id" fromClass="Sylius\Component\Addressing\Model\AddressLogEntry">
<identifiers>
<values>
<value>objectId</value>
</values>
</identifiers>
</uriVariable>
</uriVariables>
<operations>
<operation class="ApiPlatform\Metadata\GetCollection">
<normalizationContext>
<values>
<value name="groups">
<values>
<value>sylius:admin:address:log_entry:show</value>
</values>
</value>
</values>
</normalizationContext>
</operation>
</operations>
</resource>
</resources>

View file

@ -10,6 +10,7 @@ parameters:
sylius.api.doctrine_extension.order_visitor_item.filter_cart.allowed_non_get_operations:
- "shop_select_payment_method"
sylius.api.paths_to_hide:
- "%sylius.security.new_api_route%/admin/address-log-entry/{id}"
- "%sylius.security.new_api_route%/admin/catalog-promotion-actions/{id}"
- "%sylius.security.new_api_route%/admin/catalog-promotion-scopes/{id}"
- "%sylius.security.new_api_route%/admin/channel-pricings/{id}"

View file

@ -1,136 +0,0 @@
<?xml version="1.0" ?>
<!--
This file is part of the Sylius package.
(c) Sylius Sp. z o.o.
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd"
>
<resource class="%sylius.model.address.class%" shortName="Address">
<attribute name="validation_groups">sylius</attribute>
<collectionOperations>
<collectionOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/addresses</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>shop:address:index</attribute>
<attribute>sylius:shop:address:index</attribute>
</attribute>
</attribute>
</collectionOperation>
<collectionOperation name="shop_post">
<attribute name="method">POST</attribute>
<attribute name="path">/shop/addresses</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>shop:address:create</attribute>
<attribute>sylius:shop:address:create</attribute>
</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>shop:address:show</attribute>
<attribute>sylius:shop:address:show</attribute>
</attribute>
</attribute>
</collectionOperation>
</collectionOperations>
<itemOperations>
<itemOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/addresses/{id}</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>admin:address:show</attribute>
<attribute>sylius:admin:address:show</attribute>
</attribute>
</attribute>
</itemOperation>
<itemOperation name="admin_put">
<attribute name="method">PUT</attribute>
<attribute name="path">/admin/addresses/{id}</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>admin:address:update</attribute>
<attribute>sylius:admin:address:update</attribute>
</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>admin:address:show</attribute>
<attribute>sylius:admin:address:show</attribute>
</attribute>
</attribute>
</itemOperation>
<itemOperation name="admin_get_log_entries">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/addresses/{id}/log-entries</attribute>
<attribute name="controller">Sylius\Bundle\ApiBundle\Controller\GetAddressLogEntryCollectionAction</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>admin:address:log_entry:show</attribute>
<attribute>sylius:admin:address:log_entry:show</attribute>
</attribute>
</attribute>
<attribute name="openapi_context">
<attribute name="summary">Retrieves the collection of AddressLogEntry resources.</attribute>
<attribute name="description">Retrieves the collection of AddressLogEntry resources</attribute>
</attribute>
</itemOperation>
<itemOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/addresses/{id}</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>shop:address:show</attribute>
<attribute>sylius:shop:address:show</attribute>
</attribute>
</attribute>
</itemOperation>
<itemOperation name="shop_delete">
<attribute name="method">DELETE</attribute>
<attribute name="path">/shop/addresses/{id}</attribute>
</itemOperation>
<itemOperation name="shop_put">
<attribute name="method">PUT</attribute>
<attribute name="path">/shop/addresses/{id}</attribute>
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>shop:address:update</attribute>
<attribute>sylius:shop:address:update</attribute>
</attribute>
</attribute>
<attribute name="normalization_context">
<attribute name="groups">
<attribute>shop:address:show</attribute>
<attribute>sylius:shop:address:show</attribute>
</attribute>
</attribute>
</itemOperation>
</itemOperations>
<property name="id" identifier="true" writable="false" />
<property name="firstName" writable="true" />
<property name="lastName" writable="true" />
<property name="city" writable="true" />
<property name="street" writable="true" />
<property name="postcode" writable="true" />
<property name="countryCode" writable="true" />
<property name="provinceCode" writable="true" />
<property name="provinceName" writable="true" />
</resource>
</resources>

View file

@ -0,0 +1,56 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\ApiBundle\StateProcessor\Post;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\Metadata\Post;
use ApiPlatform\State\ProcessorInterface;
use Sylius\Bundle\ApiBundle\Context\UserContextInterface;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Webmozart\Assert\Assert;
/**
* @implements ProcessorInterface<AddressInterface>
*/
final readonly class AddressProcessor implements ProcessorInterface
{
public function __construct(
private ProcessorInterface $persistProcessor,
private UserContextInterface $userContext,
) {
}
/**
* @param AddressInterface $data
*/
public function process($data, Operation $operation, array $uriVariables = [], array $context = [])
{
Assert::isInstanceOf($data, AddressInterface::class);
Assert::isInstanceOf($operation, Post::class);
$user = $this->userContext->getUser();
$customer = $user instanceof ShopUserInterface ? $user->getCustomer() : null;
if (null !== $customer) {
$data->setCustomer($customer);
if (null === $customer->getDefaultAddress()) {
$customer->setDefaultAddress($data);
}
}
return $this->persistProcessor->process($data, $operation, $uriVariables, $context);
}
}