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

[RFC] Address book #229

Merged
merged 34 commits into from
Aug 20, 2018
Merged

[RFC] Address book #229

merged 34 commits into from
Aug 20, 2018

Conversation

jseparovic1
Copy link
Contributor

@jseparovic1 jseparovic1 commented Oct 26, 2017

  • GET /address-book

  • POST /address-book

  • PUT /address-book/{id}

  • DELETE /address-book/{id}

  • PATCH /address-book/{id}/default

  • Add tests

  • Add translation labels

@lchrusciel
Copy link
Member

Each of class misses empty line at the end of the file. Also, there are a few redundant comments. Did you think about using an Address VO from model namespace?

@lchrusciel
Copy link
Member

Also, @jseparovic1 can you share your thoughts here or in Slack PM what are your experiences with working with ShopApiPlugin? Was it easy to add these endpoints?

@antonioperic
Copy link
Contributor

@lchrusciel we spoke with @pjedrzejewski and agree to not implement PATCH for updating as PUT is enough. Just to have in mind for reviewing code

@lchrusciel
Copy link
Member

@antonioperic @jseparovic1 please ping me, when it will be ready for review. Or should I check it right now?

@jseparovic1
Copy link
Contributor Author

@lchrusciel i need to finish unit tests, but you could check it right now, and let me know if there is something to change.

@jseparovic1 jseparovic1 changed the title [WIP] Address book [RFC] Address book Nov 2, 2017
@lchrusciel
Copy link
Member

@jseparovic1 would it be a problem for you to split this PR into smaller ones?

use Sylius\ShopApiPlugin\Command\UpdateAddress;
use Sylius\ShopApiPlugin\Model\Address;

class UpdateAddressSpec extends ObjectBehavior
Copy link
Member

Choose a reason for hiding this comment

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

some of the specs are missing a final keyword

ProvinceInterface $province,
FactoryInterface $addressFactory
) {
$tokenStorage->getToken()->willReturn($userToken);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to fetch the token inside a controller instead of the handler. It would decouple our logic from authorization mechanism, what is crucial if one would like to use an oauth for example. Or other open id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, i will refactor this. So i should fetch token inside a controller and pass it to related command and then in handler just get user from the token ?

Copy link
Member

Choose a reason for hiding this comment

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

I think we could even get a user in the controller and just add its email here. Security is a part of infrastructure at the end. And even if I didn't introduce proper namespace separation(yet ;)) we could try to follow that rule, I suppose. What's your opinion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so i will get user from token , and pass its email to a command. The in the handler i will resolve user from email. This sounds nice to me and i agree that getting user from token in handler is really bad idea because of tightly coupling. I have few more situations with getting current user, so I want to be sure it is done in proper way.

private $address;

/**
* CreateAddress constructor.
Copy link
Member

Choose a reason for hiding this comment

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

these comments are redundant. There are at least 6 more to delete.

@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);
Copy link
Member

Choose a reason for hiding this comment

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

I have to refactor the plugin to introduce it in the whole codebase... Just a side note

src/Resources/config/services/actions/address_book.xml Outdated Show resolved Hide resolved
src/Resources/translations/validators.en.yml Outdated Show resolved Hide resolved
tests/Controller/AddressBookCreateAddressApiTest.php Outdated Show resolved Hide resolved
@jseparovic1
Copy link
Contributor Author

@lchrusciel I refactored this like we agreed. Unfortunately I don't have time right now for splitting up this into smaller PR.

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.

It is good to merge, but rebase is needed.

*
* @return Address
*/
public static function createFromRequest(Request $request)
Copy link
Member

Choose a reason for hiding this comment

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

Missing return type

@lchrusciel
Copy link
Member

The tests are failing... :(

@pjedrzejewski
Copy link
Member

@jseparovic1 Hi! Do you guys plan to update this PR? :)

@jseparovic1
Copy link
Contributor Author

@pjedrzejewski Hi, i plan to update it in upcoming weeks. Since we have tight project deadline I decide to customize this feature for our needs and finish PR later :)

@lchrusciel
Copy link
Member

@jseparovic1 are you adjusting forked code or used a custom implementation? I'm just wondering how it will work in such a case.

Also, sorry for long feedback loops.

@jseparovic1
Copy link
Contributor Author

@lchrusciel forked code remains the same, i created new classes under my project namespace. It should work like a charm :)

@lchrusciel
Copy link
Member

I would love to merge it, but we need tests to pass to do it. :(

@jseparovic1
Copy link
Contributor Author

@lchrusciel I installed php 7.2 and found an error so text are now fixed. PR should be ready now.

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.

Thank you very much for all your work! I hope you enjoyed working with the plugin. Most of my comments are just some small changes but for example, better validation message is pretty important. Will you find some time to fix the PR?

src/Command/CreateAddress.php Outdated Show resolved Hide resolved

namespace Sylius\ShopApiPlugin\Command;

class RemoveAddress
Copy link
Member

Choose a reason for hiding this comment

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

missing final

src/Controller/AddressBook/CreateAddressAction.php Outdated Show resolved Hide resolved
}

/** @var ShopUserInterface $shopUser */
$shopUser = $this->tokenStorage->getToken()->getUser();
Copy link
Member

Choose a reason for hiding this comment

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

Assert::isInstanceOf($user, ShopUserInterface::class);

src/Controller/AddressBook/SetDefaultAddressAction.php Outdated Show resolved Hide resolved
src/Resources/config/routing.yml Outdated Show resolved Hide resolved
tests/Controller/AddressBookRemoveAddressApiTest.php Outdated Show resolved Hide resolved
tests/DataFixtures/ORM/address.yml Show resolved Hide resolved
tests/DataFixtures/ORM/customer.yml Show resolved Hide resolved
@lchrusciel lchrusciel added this to the v1.1.0 milestone Mar 26, 2018
@mamazu
Copy link
Member

mamazu commented Aug 16, 2018

This would be a great feature to have.

@pamil
Copy link
Contributor

pamil commented Aug 20, 2018

Woah, I hope I got rebasing right 🎉

@pamil pamil closed this Aug 20, 2018
@pamil pamil reopened this Aug 20, 2018
@pamil pamil closed this Aug 20, 2018
@pamil pamil reopened this Aug 20, 2018
@pamil pamil merged commit 20a55b1 into Sylius:master Aug 20, 2018
@pamil
Copy link
Contributor

pamil commented Aug 20, 2018

Thank you, Jurica!

@mamazu
Copy link
Member

mamazu commented Aug 21, 2018

  • Add documentation :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants