-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Product reviews API #8772
Product reviews API #8772
Conversation
$productCode | ||
); | ||
|
||
$productReview->setStatus(ReviewInterface::STATUS_ACCEPTED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never do setStatus
but use State Machine instead. :) http://docs.sylius.org/en/latest/book/architecture/state_machine.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I will make the change.
99d8265
to
41e6c2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Please apply these minor changes 😃
docs/api/product_reviews.rst
Outdated
| author | Customer author for product review (This is customer that added the | | ||
| | product review; this will contain customer resource information) | | ||
+------------------+------------------------------------------------------------------------------------------------+ | ||
| status | Status of product review(New, Accepted, Rejected) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before (
docs/api/product_reviews.rst
Outdated
+---------------+----------------+----------------------------------------------------------+ | ||
| comment | request | Product review comment | | ||
+---------------+----------------+----------------------------------------------------------+ | ||
| rating | request | Product review rating(1..5) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before (
docs/api/product_reviews.rst
Outdated
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank line
docs/api/product_reviews.rst
Outdated
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary blank line
docs/api/product_reviews.rst
Outdated
+---------------+----------------+----------------------------------------------------------+ | ||
| comment | request | Product review comment | | ||
+---------------+----------------+----------------------------------------------------------+ | ||
| rating | request | Product review rating(1..5) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before (
|
||
/** | ||
* @param ProductInterface $product | ||
* @param ProductReview $productReview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProductReviewInterface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I tried to find the "ProductReviewInterface" but it does not exists, only "ReviewInterface".
And because this class refers to the Product Review Api, I thought will be a good fit to use "ProductReview" model. Or I should create a interface for ProductReview model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, there should be ReviewInterface
instead of ProductReview
😃
lastName: King | ||
email: example.king@example.com | ||
emailCanonical: example.king@example.com | ||
Sylius\Component\Core\Model\Product: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line before this line
comment: "mug_review_bad_comment" | ||
author: "@customer_example1" | ||
status: "accepted" | ||
reviewSubject: "@product1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line at the end of file
@@ -0,0 +1,92 @@ | |||
{ | |||
"id": @integer@, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation should be with 4 spaces in this file and other jsons
}, | ||
"createdAt": @string@, | ||
"updatedAt": @string@ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line at the end of file here and in other jsons
01cca12
to
72ed226
Compare
72ed226
to
ca4a90a
Compare
* | ||
* @return QueryBuilder | ||
*/ | ||
public function createQueryBuilderByProductCode(string $locale, string $productCode): QueryBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding methods to an interface is a BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pamil, in this case how can proceed next? Should we put the methods only into the ProductReviewRepository?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our proposed BC promise (#8901), it isn't a BC break 🎉
_sylius: | ||
state_machine: | ||
graph: sylius_product_review | ||
transition: reject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line at the end of file.
|
||
/** | ||
* @param mixed $id | ||
* @param string $productCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doubled space after string
/** | ||
* @test | ||
*/ | ||
public function it_allows_create_product_review() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it_allows_creating_new_product_review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @Zales0123,
For these methods names I checked also tests/Controller/ProductVariantApiTest.php witch have added the same method name's logic: "it_allows_create_product_variant"; it means that for tests/Controller/ProductVariantApiTest.php is also incorect? if not, what is the difference between ProductReviewApiTest.php and ProductVariantApiTest.php, why for one is correct and for the other one, not?
Thank you.
Paul.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the name of the methods the most important requirement is language correctness :) So even if somewhere else method names are named incorrectly (from the grammatical point of view) we should on writing new ones as perfect as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, then I will rewrite, these methods name, with the good ones, for tests/Controller/ProductReviewApiTest.php.
{ | ||
"title": "J_REVIEW", | ||
"rating": "3", | ||
"comment": "J_REVIEW_COMMENT", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't be afraid of using some more natural exemplary data, these are of course not wrong, but less natural to read. Tests are good place to place easter eggs in code (look at our Behat scenarios and I'll see what I mean 😄 )
/** | ||
* @test | ||
*/ | ||
public function it_allows_delete_product_review() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it_allows_deleting_...
here and below.
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allows_accept_product_review_if_it_has_not_new_status() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it_does_not_allows_accepting_...
and so on.
docs/api/product_reviews.rst
Outdated
| status | Status of product review (New, Accepted, Rejected) | | ||
+------------------+------------------------------------------------------------------------------------------------+ | ||
| reviewSubject | This is the review subject for the product review. For this case of the product review, this | | ||
| | will contains a product resource | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this contains...
or this will contain...
docs/api/product_reviews.rst
Outdated
"status": "new", | ||
"reviewSubject": { | ||
"name": "MUG-TH", | ||
"id": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
should be in the first position here and in other examples
docs/api/product_reviews.rst
Outdated
Example | ||
^^^^^^^ | ||
|
||
To create new product review for the product with ``code = MUG-TH`` use the below method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a new product
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
# | ||
# @author Paul Stoica <paul.stoica18@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using author docblocks anymore, because they are just redundant (data can be fetched from git history), please remove it from here and other files
* | ||
* @return QueryBuilder | ||
*/ | ||
public function createQueryBuilderByProductCode(string $locale, string $productCode): QueryBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our proposed BC promise (#8901), it isn't a BC break 🎉
@paulstoica, please rebase your branch and provide other fixes :) |
} | ||
} | ||
}, | ||
"createdAt": @string@, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@string@.isDateTime()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we used to surround @string@
matches with "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it is good to go :)
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Paul Stoica <paul.stoica18@gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not adding author doc blocks anymore. Relevant PR #8882
*/ | ||
final class ProductReviewApiTest extends JsonApiTestCase | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
$product = $productReviewsData['product1']; | ||
|
||
$data = | ||
<<<EOT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indent
/** | ||
* @test | ||
*/ | ||
public function it_allows_indexing_product_reviews() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing denied access test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lchrusciel there is a test method: "it_does_not_allows_showing_product_review_list_when_access_is_denied", or what do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just missed it
@paulstoica will you be able to make this few final fixes from @lchrusciel? It would be great to have it merged. Also there are some fails on travis which seems to have no connection with proposed changes, maybe rebase with current |
product_variants | ||
product_reviews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One would be enough
* :doc:`/api/product_variants` | ||
* :doc:`/api/product_reviews` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
|
||
final class ProductReviewApiTest extends JsonApiTestCase | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, I'll add an entry in UPGRADE.md for these added repository methods, just to have everything covered.
Thanks Paul for your effort (and patience)! 🎉 |
@pamil, you're welcome. But, how @lchrusciel said, I need also to remove from the documentation one "product_reviews" text because I saw that is a duplication there(I think because of an old conflict that I had). Can I work in this pull request, or how we will proceed, if it was closed? |
@paulstoica I've already made it for you in #9084. Anyway, the flow in these cases is to open an another PR (based on the updated remote branch the previous PR have been merged into). |
Product reviews API
Product reviews API
This pull request is strong related to the #8753 ticket that I open.
I added API endpoints for Product Reviews: get, post, put, patch, show and in addition I added also other two endpoints for accepting/rejecting a product review.
In this pull request are all the changes. Also in this pull request is the documentation for this Product Reviews API.