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

Add save, update_tracking, and cancel actions to FulfillmentOrderFulfillment resource #639

Conversation

karmakaze
Copy link
Contributor

This PR adds the following POST requests:

POST fulfillments (via FulfillmentOrderFulfillment.save)
POST fulfillments/:fulfillment_id/update_tracking
POST fulfillments/:fulfillment_id/cancel

GET requests are in PR #633
FulfillmentOrder actions move, cancel, close are in PR #635
FulfillmentOrder actions fulfillment_request (+ accept/reject), cancellation_request (+ accept/reject) are in PR #637
Subsequent PRs will add other fulfillment order related requests to relevant resources.

Since all that's really needed is the fulfillment_id, if it's known you can do (rather than querying it first):

  FulfillmentOrderFulfillment.new(id: <the-fulfillment-id>).update_tracking(<params>)

Notes to reviewer:

  • there's already a Fulfillment resource which I haven't yet determined is the same/compatible with FO fulfillments so created a new resource FulfillmentOrderFulfillment
  • the specific statuses used in the tests may not make logical sense in terms of fulfillment order/fulfillment lifecycle. the tests do verify proper request dispatching and serialization

@karmakaze karmakaze requested a review from a team as a code owner November 14, 2019 16:27
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch from 7f5e63c to 90ab4b6 Compare November 14, 2019 22:34
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 43505f9 to 797e348 Compare November 14, 2019 22:42
lib/shopify_api/resources/fulfillment_order_fulfillment.rb Outdated Show resolved Hide resolved
test/fulfillment_order_fulfillment_test.rb Outdated Show resolved Hide resolved
test/fulfillment_order_fulfillment_test.rb Outdated Show resolved Hide resolved
test/fulfillment_order_fulfillment_test.rb Outdated Show resolved Hide resolved
test/fulfillment_order_fulfillment_test.rb Outdated Show resolved Hide resolved
test/fulfillment_order_fulfillment_test.rb Outdated Show resolved Hide resolved
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch from 366a1e8 to 4ce57df Compare November 26, 2019 18:37
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 797e348 to 130deca Compare November 26, 2019 20:16
test/fulfillment_v2_test.rb Outdated Show resolved Hide resolved
test/fulfillment_v2_test.rb Outdated Show resolved Hide resolved
test/fulfillment_v2_test.rb Outdated Show resolved Hide resolved
test/fulfillment_v2_test.rb Outdated Show resolved Hide resolved
test/fulfillment_v2_test.rb Outdated Show resolved Hide resolved
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 130deca to d1fd0c8 Compare November 28, 2019 15:39
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch 2 times, most recently from 8c5ddaf to 41b60d0 Compare December 2, 2019 20:07
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from d1fd0c8 to 0c557e7 Compare December 2, 2019 20:08
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 0c557e7 to a82a554 Compare December 10, 2019 20:09
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch 2 times, most recently from f1da843 to 46935ea Compare December 16, 2019 18:21
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from a82a554 to 1c3b49d Compare December 16, 2019 18:22
Copy link

@froot froot left a comment

Choose a reason for hiding this comment

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

Not finished reviewing this yet, will finish up tomorrow. Here are some of my existing thoughts.

@@ -6,8 +6,32 @@ def order_id
@prefix_options[:order_id]
end

def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end
def cancel(using_fulfillment_orders: false)
Copy link

Choose a reason for hiding this comment

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

The new cancel endpoint does functionally the same thing as the old one. So why don't we just leave the original cancel method as is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we had decided on this, everyone can use the existing endpoint.

def complete; load_attributes_from_response(post(:complete, {}, only_id)); end
def open; load_attributes_from_response(post(:open, {}, only_id)); end

def create
Copy link

Choose a reason for hiding this comment

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

I'm unsure what's provided by ActiveResource::Base but is this intended to override self.create the class method instead of the instance method? What about .save? We still need to support both POST /admin/api/2020-01/orders/#{order_id}/fulfillments.json and POST /admin/api/2020-01/fulfillments.json no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that makes sense, I forgot about save being used for create.

@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch from 46935ea to 225ad9f Compare December 16, 2019 21:36
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 1c3b49d to 744ef60 Compare December 17, 2019 18:40
@@ -9,5 +9,26 @@ def order_id
def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end
def complete; load_attributes_from_response(post(:complete, {}, only_id)); end
def open; load_attributes_from_response(post(:open, {}, only_id)); end

def self.create(attributes = {})
Copy link

Choose a reason for hiding this comment

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

I think self.create is synonymous to calling new then save. https://api.rubyonrails.org/v3.2.6/classes/ActiveResource/Base.html#method-c-create so we should be good by just overriding save.

fulfillment
end

def save
Copy link

Choose a reason for hiding this comment

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

We still need to support the ability to create fulfillments using the old endpoint, as well as the new fulfillment create:

Screen Shot 2019-12-18 at 11 56 37 AM

We can do so by inspecting the passed in params and deciding if the client intended to use the legacy/new endpoint.

@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment-cancellation-request branch 2 times, most recently from fc57449 to c5e8b3b Compare January 9, 2020 21:06
@karmakaze karmakaze closed this Jan 9, 2020
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from 744ef60 to 6fc2312 Compare January 9, 2020 23:09
@karmakaze karmakaze reopened this Jan 10, 2020
Copy link
Contributor

@linzhao125 linzhao125 left a comment

Choose a reason for hiding this comment

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

LGTM! I only have one question about `attributes.delete(:order_id).

@@ -9,5 +9,41 @@ def order_id
def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end
def complete; load_attributes_from_response(post(:complete, {}, only_id)); end
def open; load_attributes_from_response(post(:open, {}, only_id)); end

def order_id=(order_id)
binding.pry
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to be removed.


def order_id=(order_id)
binding.pry
attributes.delete('order_id') || attributes.delete(:order_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it calling delete twice? I am a bit confused here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally the attributes contains string keys. When I was refactoring this, some versions ended up with symbol keys :order_id. Finally in the end, neither is needed as the prefix_options are set explicitly by client code and not inferred from attributes so removing this.

lib/shopify_api/resources/fulfillment_order.rb Outdated Show resolved Hide resolved
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from e34a461 to a615ff8 Compare January 10, 2020 18:51
@karmakaze karmakaze force-pushed the fulfillment-orders-fulfillment branch from a615ff8 to 4842030 Compare January 10, 2020 19:31
Copy link
Contributor

@tanema tanema left a comment

Choose a reason for hiding this comment

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

Just wondering why you are doing one thing

end

fulfillmentV2 = FulfillmentV2.new(attributes)
result = fulfillmentV2.save
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a way of migrating fulfillments? Why are you doing this?

Copy link
Contributor Author

@karmakaze karmakaze Jan 13, 2020

Choose a reason for hiding this comment

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

We do this not for any sort of migration but because we have different endpoints with different supported operations. We have this situation because the backend has two REST paths for fulfillments, the existing pre-FulfillmentOrder one at /order/#/fulfillments and the new FulfillmentOrder based one at /fulfillments. To make them interoperable we use the Fulfillment resource which routes to the FulfillmentV2 resource when we need to use the /fulfillments path for an operation. Whenever reading a response, we always convert FulfillmentV2 back to Fulfillment.

@karmakaze karmakaze merged commit cc1307d into fulfillment-orders-fulfillment-cancellation-request Jan 13, 2020
@karmakaze karmakaze deleted the fulfillment-orders-fulfillment branch January 13, 2020 18:03
@karmakaze karmakaze restored the fulfillment-orders-fulfillment branch January 13, 2020 21:16
@karmakaze karmakaze deleted the fulfillment-orders-fulfillment branch January 14, 2020 15:41
@linzhao125 linzhao125 temporarily deployed to rubygems January 27, 2020 20:49 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants