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
Create API v1 with customers endpoint #8891
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.
Nice and though one! 💪
Reading the initial issue (#8788), I'm a bit concerned about the needed attributes (see my comment below), but also about the feature toggle mentioned in the acceptance criteria: "8- Feature exists behind a feature toggle"
module Api | ||
module V1 | ||
class CustomerSerializer < BaseSerializer | ||
attributes :id, :enterprise_id, :first_name, :last_name, :code, :email |
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.
Reading the initial issue: #8788, I was wondering if there were some necessary attributes missing?
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.
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.
oh yes, I didn't see that step2 ! Thanks !
- Inherits from ActionController::API - Lots of superfluous junk removed
Update translation key namespacing
And add new customers routes. Disable them in production for now.
Add customer serializer
Include test helpers
https://jsonapi.org/examples/#pagination Update schema for collections rendered with pagination data
It raised an error: NoMethodError: undefined method `map' for nil:NilClass
We don't know what unknown errors would report. They could expose sensitive data. So let's not pass that data on to the public while we have the full details in Bugsnag. Also, let's not catch Exception because that could catch interrupts to gracefully shut down the application.
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.
Went through this. Looks good to my eye 🚀
Hey @mkllnk , After staging, the server displays the Checked the docs, and tested the following endpoints:
Whhoaa. Awesome. We can now create customers via the console 👀 🎉 🚀 However, it did not really seemed to work correctly for first, last and code: the request: Created this customer: Is there an obvious reason for this, that I might be missing? I'll need to stop here and continue testing later. |
I'm not really done with testing all the test cases above (thanks for adding them Maikel) nor eventual regression testing. I'm not sure on the risk of regressions this PR introduces. From the discussion above, it seems the feature toggle is not yet implemented here. I also could not find any reference to Flipper in the code, or anything on how to activate/deactivate this feature. On the other hand, we should merge asap to unblock work on this funded feature. So, moving to ready to go, feel free to merge. |
end | ||
|
||
def customer_params | ||
params.require(:customer).permit(:email, :enterprise_id) |
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.
This needs the other params like :first_name
, :last_name
, right?
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.
(That's why they didn't show up in the test @filipefurtad0 did above...)
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.
Yes, that's in the next PR which adds all the specified attributes.
it "informs about invalid pages" do | ||
get "/api/v1/customers", params: { page: "0" } | ||
expect(json_response_ids).to eq nil | ||
expect(json_error_detail).to eq 'expected :page >= 1; got "0"' |
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.
This seems like a weird case...
We could just avoid it entirely by forcing the value to always be positive at the point we're doing the pagination, eg:
params[:per_page].to_i.clamp(1..)
What do you think?
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.
Tempting. Much simpler. But I think that we should give people direct feedback about invalid parameters. It may have been a typo and we don't want to let our sever work if not needed. And someone may have intended to get page 10 and then got page 1 instead, may not notice.
What? Why?
Step 2 of #8787
Rebased version of #8326. We are setting the scene for the new OFN API V1 and add the customers endpoint as first example.
What should we test?
/api-docs
to see what kind of requests need testing.curl
in the command line if you provide your API key.Examples:
Release notes
Changelog Category: User facing changes
The title of the pull request will be included in the release notes.
Dependencies
We are waiting for:
Documentation updates
Let's not publish this yet but we can upload the new swagger file to Swaggerhub at some point. In the meantime, staging servers will have documentation at
/api-docs
.