Skip to content

Commit

Permalink
minor #449 fixed product reviews by product code route by api convent…
Browse files Browse the repository at this point in the history
…ion (antonioperic)

This PR was merged into the 1.0-dev branch.

Discussion
----------



Commits
-------

a63a76d fixed product reviews by product code route by api convention
41389e0 fixed tests for adding and getting reviews for products by product slug
87de8f5 revert
3cadb9c improved product api routing configuration
549c78b revert doctrine config
b173ba7 updated readme file
  • Loading branch information
mamazu authored Jun 9, 2019
2 parents 31b2ca0 + b173ba7 commit 1ecf970
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
17 changes: 9 additions & 8 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

* The product routes have been changed:

| Old Route | New route |
|:-------------------------------------|:-------------------------------------|
| `products/{code}` | `products/by-code/{code}` |
| `products-by-slug/{slug}` | `products/by-slug/{slug}` |
| `products/{code}/reviews` | `products/by-code/{code}/reviews` |
| `products-reviews-by-slug/{slug}` | `products/by-slug/{slug}/reviews` |
| `taxon-products/{code}` | `taxon-products/by-code/{taxonCode}` |
| `taxon-products-by-slug/{taxonSlug}` | `taxon-products/by-slug/{taxonSlug}` |
| Old Route | New route |
|:--------------------------------------|:---------------------------------------|
| `products/{code}` | `products/by-code/{code}` |
| `products-by-slug/{slug}` | `products/by-slug/{slug}` |
| `products/{code}/reviews` | `products/by-code/{code}/reviews` |
| `products-reviews-by-slug/{slug}` | `products/by-slug/{slug}/reviews` |
| `taxon-products/{code}` | `taxon-products/by-code/{taxonCode}` |
| `taxon-products-by-slug/{taxonSlug}` | `taxon-products/by-slug/{taxonSlug}` |
| `product/by-slug/{slug}/reviews` | `products/by-slug/{slug}/reviews` |

# UPGRADE FROM 1.0.0-beta.17 to 1.0.0-beta.18

Expand Down
2 changes: 1 addition & 1 deletion doc/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ paths:
description: "Show a product with the given code."
schema:
$ref: "#/definitions/ProductDetails"
/{channelCode}/product/by-slug/{slug}/reviews:
/{channelCode}/products/by-slug/{slug}/reviews:
parameters:
- $ref: "#/parameters/ChannelCode"
- name: "slug"
Expand Down
24 changes: 12 additions & 12 deletions src/Resources/config/routing/productByCode.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
sylius_shop_api_product_show_details_by_code:
path: /products/by-code/{code}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_code_action

sylius_shop_api_product_show_catalog_by_code:
path: /taxon-products/by-code/{taxonCode}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_code_action

sylius_shop_api_product_show_reviews_by_code:
path: /products/by-code/{code}/reviews
methods: [GET]
Expand All @@ -21,3 +9,15 @@ sylius_shop_api_add_product_review_by_code:
methods: [POST]
defaults:
_controller: sylius.shop_api_plugin.controller.product.add_review_by_code_action

sylius_shop_api_product_show_details_by_code:
path: /products/by-code/{code}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_code_action

sylius_shop_api_product_show_catalog_by_code:
path: /taxon-products/by-code/{taxonCode}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_code_action
32 changes: 16 additions & 16 deletions src/Resources/config/routing/productBySlug.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
sylius_shop_api_product_show_details_by_slug:
path: /products/by-slug/{slug}
sylius_shop_api_product_show_reviews_by_slug:
path: /products/by-slug/{slug}/reviews
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_slug_action
_controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_slug_action
requirements:
slug: .+

sylius_shop_api_product_show_catalog_by_slug:
path: /taxon-products/by-slug/{taxonSlug}
methods: [GET]
sylius_shop_api_add_product_review_by_slug:
path: /products/by-slug/{slug}/reviews
methods: [POST]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_slug_action
_controller: sylius.shop_api_plugin.controller.product.add_review_by_slug_action
requirements:
taxonSlug: .+
slug: .+

sylius_shop_api_product_show_reviews_by_slug:
path: /product/by-slug/{slug}/reviews
sylius_shop_api_product_show_details_by_slug:
path: /products/by-slug/{slug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.show_product_reviews_by_slug_action
_controller: sylius.shop_api_plugin.controller.product.show_product_details_by_slug_action
requirements:
slug: .+

sylius_shop_api_add_product_review_by_slug:
path: /product/by-slug/{slug}/reviews
methods: [POST]
sylius_shop_api_product_show_catalog_by_slug:
path: /taxon-products/by-slug/{taxonSlug}
methods: [GET]
defaults:
_controller: sylius.shop_api_plugin.controller.product.add_review_by_slug_action
_controller: sylius.shop_api_plugin.controller.product.show_product_catalog_by_taxon_slug_action
requirements:
slug: .+
taxonSlug: .+
10 changes: 5 additions & 5 deletions tests/Controller/Product/ProductAddReviewBySlugApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function it_adds_review_to_product(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -47,7 +47,7 @@ public function it_adds_review_to_the_product_for_registered_user(): void
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponseCode($response, Response::HTTP_CREATED);
Expand All @@ -69,7 +69,7 @@ public function it_does_not_allow_to_add_product_review_by_slug_in_non_existent_
"email": "oliver@example.com"
}
EOT;
$this->client->request('POST', '/shop-api/SPACE_KLINGON/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/SPACE_KLINGON/products/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand All @@ -92,7 +92,7 @@ public function it_does_not_allow_to_add_review_when_rating_is_out_of_bounds():
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_rating', Response::HTTP_BAD_REQUEST);
Expand All @@ -115,7 +115,7 @@ public function it_does_not_allow_to_add_review_when_rating_email_is_not_valid()
}
EOT;

$this->client->request('POST', '/shop-api/WEB_GB/product/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);
$this->client->request('POST', '/shop-api/WEB_GB/products/by-slug/mug/reviews', [], [], self::CONTENT_TYPE_HEADER, $data);

$response = $this->client->getResponse();
$this->assertResponse($response, 'reviews/add_review_failed_email', Response::HTTP_BAD_REQUEST);
Expand Down
4 changes: 2 additions & 2 deletions tests/Controller/Product/ProductShowReviewsBySlugApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function it_shows_reviews_for_product_by_slug(): void
{
$this->loadFixturesFromFiles(['shop.yml', 'customer.yml', 'mug_review.yml']);

$this->client->request('GET', '/shop-api/WEB_GB/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/WEB_GB/products/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'product/product_review_list_page_by_slug_response', Response::HTTP_OK);
Expand All @@ -29,7 +29,7 @@ public function it_does_not_show_product_reviews_by_slug_in_non_existent_channel
{
$this->loadFixturesFromFiles(['channel.yml']);

$this->client->request('GET', '/shop-api/SPACE_KLINGON/product/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER);
$this->client->request('GET', '/shop-api/SPACE_KLINGON/products/by-slug/logan-mug/reviews', [], [], self::CONTENT_TYPE_HEADER);
$response = $this->client->getResponse();

$this->assertResponse($response, 'channel_has_not_been_found_response', Response::HTTP_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"pages": 3,
"total": 25,
"_links": {
"self": "\/shop-api\/WEB_GB\/product\/by-slug\/logan-mug\/reviews?page=1&limit=10",
"first": "\/shop-api\/WEB_GB\/product\/by-slug\/logan-mug\/reviews?page=1&limit=10",
"last": "\/shop-api\/WEB_GB\/product\/by-slug\/logan-mug\/reviews?page=3&limit=10",
"next": "\/shop-api\/WEB_GB\/product\/by-slug\/logan-mug\/reviews?page=2&limit=10"
"self": "\/shop-api\/WEB_GB\/products\/by-slug\/logan-mug\/reviews?page=1&limit=10",
"first": "\/shop-api\/WEB_GB\/products\/by-slug\/logan-mug\/reviews?page=1&limit=10",
"last": "\/shop-api\/WEB_GB\/products\/by-slug\/logan-mug\/reviews?page=3&limit=10",
"next": "\/shop-api\/WEB_GB\/products\/by-slug\/logan-mug\/reviews?page=2&limit=10"
},
"items": [
{
Expand Down

0 comments on commit 1ecf970

Please sign in to comment.