[API][Shop] Make Province GET endpoint to be subresources of Country

This commit is contained in:
Grzegorz Sadowski 2024-09-30 12:12:53 +02:00
parent 1c33c35d80
commit 0ccee33c9d
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
6 changed files with 19 additions and 9 deletions

View file

@ -18,7 +18,15 @@
>
<resource class="%sylius.model.province.class%">
<operations>
<operation name="sylius_api_shop_province_get" class="ApiPlatform\Metadata\Get" uriTemplate="/shop/provinces/{code}">
<operation
name="sylius_api_shop_province_get"
class="ApiPlatform\Metadata\Get"
uriTemplate="/shop/countries/{countryCode}/provinces/{provinceCode}"
>
<uriVariables>
<uriVariable parameterName="countryCode" fromClass="%sylius.model.country.class%" fromProperty="provinces" />
<uriVariable parameterName="provinceCode" fromClass="%sylius.model.province.class%"/>
</uriVariables>
<normalizationContext>
<values>
<value name="groups">

View file

@ -10,13 +10,13 @@
"name": "United States",
"provinces": [
{
"@id": "\/api\/v2\/shop\/provinces\/US-MI",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-MI",
"@type": "Province",
"code": "US-MI",
"name": "Minnesota"
},
{
"@id": "\/api\/v2\/shop\/provinces\/US-WY",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-WY",
"@type": "Province",
"code": "US-WY",
"name": "Wyoming"

View file

@ -11,13 +11,13 @@
"name": "United States",
"provinces": [
{
"@id": "\/api\/v2\/shop\/provinces\/US-MI",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-MI",
"@type": "Province",
"code": "US-MI",
"name": "Minnesota"
},
{
"@id": "\/api\/v2\/shop\/provinces\/US-WY",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-WY",
"@type": "Province",
"code": "US-WY",
"name": "Wyoming"

View file

@ -6,13 +6,13 @@
"name": "United States",
"provinces": [
{
"@id": "\/api\/v2\/shop\/provinces\/US-MI",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-MI",
"@type": "Province",
"code": "US-MI",
"name": "Minnesota"
},
{
"@id": "\/api\/v2\/shop\/provinces\/US-WY",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-WY",
"@type": "Province",
"code": "US-WY",
"name": "Wyoming"

View file

@ -1,6 +1,6 @@
{
"@context": "\/api\/v2\/contexts\/Province",
"@id": "\/api\/v2\/shop\/provinces\/US-WY",
"@id": "\/api\/v2\/shop\/countries\/US\/provinces\/US-WY",
"@type": "Province",
"code": "US-WY",
"name": "Wyoming"

View file

@ -33,7 +33,9 @@ final class ProvincesTest extends JsonApiTestCase
/** @var ProvinceInterface $province */
$province = $fixtures['province_US_WY'];
$this->requestGet(sprintf('/api/v2/shop/provinces/%s', $province->getCode()));
$this->requestGet(
sprintf('/api/v2/shop/countries/%s/provinces/%s', $province->getCountry()->getCode(), $province->getCode()),
);
$this->assertResponse($this->client->getResponse(), 'shop/province/get_province_response');
}