Skip to content
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

Merged
merged 24 commits into from
Jan 5, 2018
Merged

Product reviews API #8772

merged 24 commits into from
Jan 5, 2018

Conversation

paulstoica
Copy link

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets #8753 Product Reviews API
License MIT

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.

@pjedrzejewski pjedrzejewski added this to the 1.1 milestone Oct 5, 2017
$productCode
);

$productReview->setStatus(ReviewInterface::STATUS_ACCEPTED);
Copy link
Member

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

Copy link
Author

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.

@GSadee GSadee added the API APIs related issues and PRs. label Oct 6, 2017
Copy link
Member

@GSadee GSadee left a 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 😃

| 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) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before (

+---------------+----------------+----------------------------------------------------------+
| comment | request | Product review comment |
+---------------+----------------+----------------------------------------------------------+
| rating | request | Product review rating(1..5) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before (

}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary blank line

}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary blank line

+---------------+----------------+----------------------------------------------------------+
| comment | request | Product review comment |
+---------------+----------------+----------------------------------------------------------+
| rating | request | Product review rating(1..5) |
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProductReviewInterface

Copy link
Author

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?

Copy link
Member

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:
Copy link
Member

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"
Copy link
Member

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@,
Copy link
Member

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@
}
Copy link
Member

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

*
* @return QueryBuilder
*/
public function createQueryBuilderByProductCode(string $locale, string $productCode): QueryBuilder;
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Member

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
Copy link
Member

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
Copy link
Member

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()
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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",
Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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.

| 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 |
Copy link
Member

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...

"status": "new",
"reviewSubject": {
"name": "MUG-TH",
"id": 1,
Copy link
Member

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

Example
^^^^^^^

To create new product review for the product with ``code = MUG-TH`` use the below method.
Copy link
Member

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>
Copy link
Member

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;
Copy link
Member

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 🎉

@GSadee
Copy link
Member

GSadee commented Oct 27, 2017

@paulstoica, please rebase your branch and provide other fixes :)

@pamil pamil added Feature New feature proposals. and removed New Feature labels Oct 27, 2017
}
}
},
"createdAt": @string@,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@string@.isDateTime()

Copy link
Member

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 "

Copy link
Member

@lchrusciel lchrusciel left a 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>
Copy link
Member

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
{

Copy link
Member

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
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing denied access test

Copy link
Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just missed it

@Zales0123
Copy link
Member

Zales0123 commented Jan 4, 2018

@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 1.1 branch would work.

@pamil pamil changed the base branch from master to 1.1 January 4, 2018 10:30
product_variants
product_reviews
Copy link
Member

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`
Copy link
Member

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
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant

Copy link
Contributor

@pamil pamil left a 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.

@pamil pamil merged commit 3f8cd17 into Sylius:1.1 Jan 5, 2018
@pamil
Copy link
Contributor

pamil commented Jan 5, 2018

Thanks Paul for your effort (and patience)! 🎉

@paulstoica
Copy link
Author

paulstoica commented Jan 5, 2018

@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?

@pamil
Copy link
Contributor

pamil commented Jan 5, 2018

@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).

@pamil pamil mentioned this pull request Jan 5, 2018
pamil added a commit to pamil/Sylius that referenced this pull request May 7, 2019
pamil added a commit to pamil/Sylius that referenced this pull request May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Feature New feature proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants