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

PUT method for shipping addresses #2036

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

aafa
Copy link
Contributor

@aafa aafa commented Jun 2, 2017

This PR

  • Adds PUT method for shipping addresses to easy out checkout process
  • Refines API tests

The reason for it is to have PUT as an idempotent version of POST with createOrUpdate logic to simplify things for the frontend.

Copy link
Contributor

@michalrus michalrus left a comment

Choose a reason for hiding this comment

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

✅ 😸
@Anna-ZZZ might want to discuss adding one more method, PUT, let’s wait!

@@ -53,6 +53,20 @@ object OrderShippingAddress {
phoneNumber = p.phoneNumber.fold(a.phoneNumber)(Some(_))
)
}

def fromCreatePatchPayload(a: OrderShippingAddress, p: CreateAddressPayload) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Anna-ZZZ might not like the identifiers. I’m cool with them, but let’s wait before merge, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Um, you're right, will fix them.


storefrontCartsApi.shippingAddress.create(addressPayload).as[TheResponse[CartResponse]]

customersApi(auth.customerId).addresses.get
Copy link
Contributor

Choose a reason for hiding this comment

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

@Anna-ZZZ, I think that was my question befooore, hmm. Maybe in withNewCustomerAuth block one shouldn’t have access to admin API like customersApi, and it should be explicitly wrapped in withDefaultAdminAuth or similar. Which would mean that we’d need to remove with DefaultAdminAuth trait and wrap alsmost all existing tests. Hmmm. Well. ¯\_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

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

Request is sent with customer auth anyways because of implicits

@aafa
Copy link
Contributor Author

aafa commented Jun 5, 2017

Going to update this a bit

for {
shippingAddresses ← q
adr ← Addresses
if adr.accountId === accountId && adr.address1 === shippingAddresses.address1 && adr.name === shippingAddresses.name
Copy link
Contributor Author

@aafa aafa Jun 5, 2017

Choose a reason for hiding this comment

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

We don't have fk to Address so I need this little hack to locate related Address for now to bootstrap ApplePay thing (gonna be used only in AP, so we're safe here). Otherwise risking to blow up this scope. I have a better plan how we can address this relation, will provide info on that later.

@aafa aafa added ready to review and removed WIP labels Jun 5, 2017
@@ -342,18 +342,19 @@ package object db {

implicit class EnrichedDBIOpt[R](val dbio: DBIO[Option[R]]) extends AnyVal {

def findOrCreate(r: DbResultT[R])(implicit ec: EC): DbResultT[R] = {
def findOrCreate(createAction: ⇒ DbResultT[R])(implicit ec: EC): DbResultT[R] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, evaluated on spot. Gonna investigate if we have more of these. Wonder why ITs are not catching this 🤔

Copy link
Contributor

@kjanosz kjanosz Jun 5, 2017

Choose a reason for hiding this comment

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

Why should ITs catch this? DbResultT by itself does not execute any action, so there wasn't any creation involved.
We spare though now allocation of DbResultT when something is actually found, which I guess is more costly than plain function allocation (call-by-name overhead).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, you right. I wasn't thinking through this carefully. I was getting unique constraint violation at the time I got to this point. And quickly assumed that was the reason.

Copy link
Contributor

@annappropriate annappropriate left a comment

Choose a reason for hiding this comment

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

Is frontend ready for this? Or separate changeset?

@@ -72,6 +87,7 @@ class OrderShippingAddresses(tag: Tag)
def * =
(id, cordRef, regionId, name, address1, address2, city, zip, phoneNumber, createdAt, updatedAt) <> ((OrderShippingAddress.apply _).tupled, OrderShippingAddress.unapply)

// FIXME this fk is not reflected in db schema @aafa
Copy link
Contributor

Choose a reason for hiding this comment

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

When?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


storefrontCartsApi.shippingAddress.create(addressPayload).as[TheResponse[CartResponse]]

customersApi(auth.customerId).addresses.get
Copy link
Contributor

Choose a reason for hiding this comment

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

Request is sent with customer auth anyways because of implicits

aafa added 2 commits June 21, 2017 18:05
# Conflicts:
#	phoenix-scala/core/app/core/db/package.scala
#	phoenix-scala/phoenix/app/phoenix/models/cord/OrderShippingAddress.scala
#	phoenix-scala/phoenix/app/phoenix/routes/admin/CartRoutes.scala
#	phoenix-scala/phoenix/app/phoenix/services/carts/CartShippingAddressUpdater.scala
#	phoenix-scala/phoenix/test/integration/AddressesIntegrationTest.scala
#	phoenix-scala/phoenix/test/integration/CartValidatorIntegrationTest.scala
#	phoenix-scala/phoenix/test/integration/ShippingMethodsIntegrationTest.scala
#	phoenix-scala/phoenix/test/integration/services/CheckoutTest.scala
#	phoenix-scala/phoenix/test/integration/services/ShippingManagerTest.scala
#	phoenix-scala/phoenix/test/integration/testutils/apis/PhoenixStorefrontApi.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants