-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Conversation
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.
✅ 😸
@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) = { |
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.
@Anna-ZZZ might not like the identifiers. I’m cool with them, but let’s wait before merge, maybe?
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.
Um, you're right, will fix them.
|
||
storefrontCartsApi.shippingAddress.create(addressPayload).as[TheResponse[CartResponse]] | ||
|
||
customersApi(auth.customerId).addresses.get |
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.
@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. ¯\_(ツ)_/¯
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.
Request is sent with customer auth anyways because of implicits
Going to update this a bit |
for { | ||
shippingAddresses ← q | ||
adr ← Addresses | ||
if adr.accountId === accountId && adr.address1 === shippingAddresses.address1 && adr.name === shippingAddresses.name |
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 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.
@@ -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] = { |
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.
Again, evaluated on spot. Gonna investigate if we have more of these. Wonder why ITs are not catching this 🤔
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.
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).
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.
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.
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.
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 |
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.
When?
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.
|
||
storefrontCartsApi.shippingAddress.create(addressPayload).as[TheResponse[CartResponse]] | ||
|
||
customersApi(auth.customerId).addresses.get |
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.
Request is sent with customer auth anyways because of implicits
# 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
This PR
The reason for it is to have PUT as an idempotent version of POST with createOrUpdate logic to simplify things for the frontend.