[PoC][API] Resolve proper IRI in admin/shop contexts#11925
Conversation
aa82aa2 to
f32016f
Compare
aab699a to
c9ab309
Compare
aba9058 to
4723946
Compare
1940564 to
17f3030
Compare
17f3030 to
d896c11
Compare
1bff68f to
2bf0ebe
Compare
2bf0ebe to
1afdc9f
Compare
1afdc9f to
5ba4d7c
Compare
99b1835 to
ef5675f
Compare
ef5675f to
5e15454
Compare
| * @When I try to see one of the items from the order placed by a customer :customer | ||
| */ | ||
| public function iTryToSeeOneOfTheItemsFromTheOrderPlacedByACustomer(): void | ||
| { | ||
| /** @var OrderInterface $order */ | ||
| $order = $this->sharedStorage->get('order'); |
There was a problem hiding this comment.
customer is never checked in this context, we are checking the last order registered in shared storage. Perhaps adjusting of a step definition and/or asserting if the ordered belongs to customer should done.
| } | ||
|
|
||
| /** | ||
| * @When I try to see one of the units from the order placed by a customer :customer |
There was a problem hiding this comment.
And in every customer aware endpoint
| if ($customer !== null && in_array('ROLE_USER', $user->getRoles(), true)) { | ||
| return $this->orderItemRepository->findOneByCustomer($id, $customer); | ||
| } | ||
|
|
||
| if ($user instanceof AdminUserInterface && in_array('ROLE_API_ACCESS', $user->getRoles(), true)) { | ||
| return $this->orderItemRepository->findOneBy(['id' => $id]); | ||
| } |
There was a problem hiding this comment.
I'm wondering if we should extract this behavior to separate classes to make it easier to override.
| } | ||
|
|
||
| if ($user instanceof AdminUserInterface && in_array('ROLE_API_ACCESS', $user->getRoles(), true)) { | ||
| return $this->shipmentRepository->findOneBy(['id' => $id]); |
There was a problem hiding this comment.
| return $this->shipmentRepository->findOneBy(['id' => $id]); | |
| return $this->shipmentRepository->find($id); |
| private function returnMatchingRouteName( | ||
| array $matchingRoutes, | ||
| string $operationType, | ||
| string$resourceClass |
There was a problem hiding this comment.
| string$resourceClass | |
| string $resourceClass |
| $pathElements = array_values(array_filter(explode('/', $path))); | ||
|
|
||
| if ('/' . $pathElements[0] !== $this->apiRoute) { | ||
| return null; | ||
| } | ||
|
|
||
| if ($pathElements[1] === PathPrefixes::SHOP_PREFIX) { | ||
| return PathPrefixes::SHOP_PREFIX; | ||
| } | ||
|
|
||
| if ($pathElements[1] === PathPrefixes::ADMIN_PREFIX) { | ||
| return PathPrefixes::ADMIN_PREFIX; | ||
| } | ||
|
|
||
| return null; |
There was a problem hiding this comment.
I'm wondering if we can reuse UriBasedSectionProvider instead of this construction. But it should be an idea for future improvements.
| </itemOperations> | ||
|
|
||
| <subresourceOperations> | ||
| <subresourceOperation name="methods_get_subresource"> |
There was a problem hiding this comment.
| <subresourceOperation name="methods_get_subresource"> | |
| <subresourceOperation name="shop_get_shipping_methods_subresource"> |
or
| <subresourceOperation name="methods_get_subresource"> | |
| <subresourceOperation name="shop_shipping_methods_subresource_get"> |
WDYT?
There was a problem hiding this comment.
Looks cool, but this subresource name couldn't be changed as it is an identifier of this operation. This is the only way I can change the operation's parameters for a subresource endpoint that is configured below
<property name="method">
<subresource resourceClass="%sylius.model.shipping_method.class%" />
</property>
| > | ||
| <class name="Sylius\Component\Core\Model\Address"> | ||
| <attribute name="id"> | ||
| <group>address:read</group> |
|
|
||
| class OrderItemRepository extends BaseOrderItemRepository implements OrderItemRepositoryInterface | ||
| { | ||
| public function findOneByCustomer($id, CustomerInterface $customer): ?OrderItemInterface |
There was a problem hiding this comment.
| public function findOneByCustomer($id, CustomerInterface $customer): ?OrderItemInterface | |
| public function findOneByIdAndCustomer($id, CustomerInterface $customer): ?OrderItemInterface |
|
Thanks, Tomasz! 🥇 |
…om slug to code (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | based on #11925 | License | MIT Commits ------- 58ce6bd [API][Product] Change identifier for shop endpoint from slug to code
…t contexts (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes after #11925 | License | MIT Commits ------- f8a6101 [API] Fixes after PR with resolving proper iri in different contexts
…om slug to code (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | based on Sylius/Sylius#11925 | License | MIT Commits ------- 58ce6bd3d4745cb281ed97374f2324fd9e0af66d [API][Product] Change identifier for shop endpoint from slug to code
…t contexts (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes after Sylius/Sylius#11925 | License | MIT Commits ------- f8a6101be7004d97dc7d112dcebccb7a36deb381 [API] Fixes after PR with resolving proper iri in different contexts
…ces (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | after #11925 | License | MIT Commits ------- 4fbbbde [API] Add missing endpoints for address and country resources
…om slug to code (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | based on Sylius/Sylius#11925 | License | MIT Commits ------- 58ce6bd3d4745cb281ed97374f2324fd9e0af66d [API][Product] Change identifier for shop endpoint from slug to code
…t contexts (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes after Sylius/Sylius#11925 | License | MIT Commits ------- f8a6101be7004d97dc7d112dcebccb7a36deb381 [API] Fixes after PR with resolving proper iri in different contexts
…om slug to code (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | based on Sylius/Sylius#11925 | License | MIT Commits ------- 58ce6bd3d4745cb281ed97374f2324fd9e0af66d [API][Product] Change identifier for shop endpoint from slug to code
…t contexts (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes after Sylius/Sylius#11925 | License | MIT Commits ------- f8a6101be7004d97dc7d112dcebccb7a36deb381 [API] Fixes after PR with resolving proper iri in different contexts
…ces (GSadee) This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | after Sylius/Sylius#11925 | License | MIT Commits ------- 4fbbbde7eb6224f733d736dc4f712d4cb2bb9378 [API] Add missing endpoints for address and country resources
This PR is first step to improve IRI that are return in responses on shop and admin endpoints.
First problem was
IriConverterthat was returning bad IRI becauseRouteNameResolverreturn first matching route without aware who was called - admin or shop. It was working bad because we break all path into two prefixes (before all entities had one path).Second problem is resources configuration: All IRI-s have to proper paths on other sites: admin and shop.
My solution:
RouteNameResolverlooks for not the first occurrence, but all matching routes and match it by current prefix.To complete this PR, we need cover all occurs IRI in entities that have path on two contexts:
maybe I forgot about one
Example:

Before
After:
