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

[$1000] Implement new Google Places API #46771

Open
rafecolton opened this issue Aug 3, 2024 · 58 comments
Open

[$1000] Implement new Google Places API #46771

rafecolton opened this issue Aug 3, 2024 · 58 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Internal Requires API changes or must be handled by Expensify staff Monthly KSv2 Reviewing Has a PR in review

Comments

@rafecolton
Copy link
Member

rafecolton commented Aug 3, 2024

Coming from #45432, please implement the new Places API as described in this comment.

We'll follow the usual process of starting with a detailed proposal, but I will assign @rojiphil directly as the Contributor here since he has the most context.

I will be the CME and will also help with getting the API key updated/installed.


View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~015599eafb1cb0d217
  • Upwork Job ID: 1819786402974465675
  • Last Price Increase: 2024-08-03
  • Automatic offers:
    • mkhutornyi | Reviewer | 103384006
    • rojiphil | Contributor | 103384007
Issue OwnerCurrent Issue Owner: @rafecolton
@rafecolton rafecolton added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 3, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 3, 2024
Copy link

melvin-bot bot commented Aug 3, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mkhutornyi (External)

Copy link

melvin-bot bot commented Aug 3, 2024

Triggered auto assignment to @Christinadobrzyn (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@rafecolton
Copy link
Member Author

Not sure if the upwork job was created, going to try re-adding the label

@rafecolton rafecolton added External Added to denote the issue can be worked on by a contributor and removed External Added to denote the issue can be worked on by a contributor labels Aug 3, 2024
Copy link

melvin-bot bot commented Aug 3, 2024

Job added to Upwork: https://www.upwork.com/jobs/~015599eafb1cb0d217

Copy link

melvin-bot bot commented Aug 3, 2024

Current assignee @mkhutornyi is eligible for the External assigner, not assigning anyone new.

@rafecolton
Copy link
Member Author

Per discussion in the linked issue, I'm assigning @rojiphil as the Contributor. @rojiphil, please provide a detailed proposal when you are able for @mkhutornyi to review. Thanks!

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 3, 2024
Copy link

melvin-bot bot commented Aug 3, 2024

📣 @mkhutornyi 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

Copy link

melvin-bot bot commented Aug 3, 2024

📣 @rojiphil 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@rafecolton rafecolton self-assigned this Aug 3, 2024
@rojiphil
Copy link
Contributor

rojiphil commented Aug 5, 2024

Thanks @rafecolton for assigning me here. I am looking into this and expect to revert in next couple of days.

@melvin-bot melvin-bot bot added the Overdue label Aug 7, 2024
@rafecolton
Copy link
Member Author

Any update on when you will be delivering the first proposal @rojiphil?

@rojiphil
Copy link
Contributor

rojiphil commented Aug 8, 2024

Any update on when you will be delivering the first proposal @rojiphil?

Almost there. I will share the update today.

@rojiphil
Copy link
Contributor

rojiphil commented Aug 8, 2024

@rafecolton @mkhutornyi A draft PR with the proposed implementation details is available in PR description here. Please have a look. We can take this further based on your feedback.

@rafecolton
Copy link
Member Author

Thanks for the initial writeup. @mkhutornyi please take a look at the proposal and let me know your thoughts.

In order to keep the discussion all in one place, @rojiphil will you please transfer the proposal here? (Feel free to edit your comment above to include the proposal details.)

I have a few initial questions and comments:

  1. Are you able to test the current API by making a real API request through our web proxy? If not, how do you plan to test? (i.e. Will you need support from an internal engineer?)
  2. Can you please add some detail around what specific changes will need to be made to the BE?
    • The current implementation in the web API essentially proxies the request to https://maps.googleapis.com/maps/api, passing along the query parameters from the front-end after injecting/replacing the api key.
    • Please detail any changes that will be made to the URL, http method, etc. Please ensure this design will remain backwards-compatible. (We either need to add a new proxy endpoint or update the existing one to differentiate between the requests and support both types.)
    • Please also detail what additional scopes need to be added to the API key, or if a new key is required. If it's possible to add scopes to the existing key rather than generate a new one, I think that would be preferred, as it will simplify the BE code a bit.
  3. I will be OOO for the rest of the month starting tomorrow, so @Christinadobrzyn can source another engineer to help you test if you are not able to test yourself. That engineer may have to recruit somebody to generate and install the new key or add scopes to the existing one.

@rojiphil
Copy link
Contributor

rojiphil commented Aug 8, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

This PR implements the scope limited to the places migration as used in NewDot.

What is the root cause of that problem?

There is no root cause as this is an improvement.

What changes do you think we should make in order to solve the problem?

Dependencies:

  1. Changes in react-native-google-places-autocomplete library which is implemented in this PR
  2. API Key updation for Places API (New) in Google Cloud
  3. BE changes to support API changes for Autocomplete (New) and Place Details(New)

The implementation details for the relevant steps as mentioned here are as follows:

Let us introduce a isNewPlacesAPI property in GooglePlacesAutocomplete component here to introduce support for Places (New) api. By default, we can set this to false here so that the current implementation of Places api is used by default. This way, we do not break existing systems using the old Places API. Further, to make use of the Places API (New), the FE can send isNewPlacesAPI here.

  1. Use HTTP POST instead of HTTP GET for Autocomplete (New) API uses as mentioned here.

For Autocomplete (New) request, we can send a HTTP POST request here and also set the new url for POST i.e. ${url}/v1/places:autocomplete. Further, we can send the request body with the supported parameters here.
In addition, we also need to update the API for Place Details (New) with url ${url}/v1/places/${rowData.place_id} here

  1. Handle the format changes in response structure for Autocomplete (New) API as mentioned here

Format changes include changing the request parameters to languageCode, includedRegionCodes and locationBias here. For the response though, we need to filter the results and handle the format changes. This is done here and here

  1. Use the required parameter fieldmask for Place Details (New) API as mentioned here. This way we can control the billing by including what we need in field mask

Let us introduce a fields property in GooglePlacesAutocomplete component here to specify the desired response fields. By default, we can set this to * here so that all the fields are sent back. In our case, we set fields to make use of Location Only (Place Details) SKU thereby reducing our API cost. The specific value of fields is set here.

  1. Use session tokens to group autocomplete and place details which will help in reduced billing. This is referenced here.

To use sessions, we can create a sessionToken state here and use uuid library to generate v4 uuids for the session. This session token will be used in every Autocomplete (New) API here. And the session token will be reset to a new uuid here after using it for the last time in the Place Details (New) API here

  1. Handle the format changes related to Place object for in response structure of Place Details (New) API as referenced here

Since the response has changed Place Details (New) API, there will not be any status. Hence, we can depend on id here and pass the details to the onPress handler. The FE saveLocationDetails is modified to support the format changes in the Place Details (New) API response.

What alternative solutions did you explore? (Optional)

@rojiphil
Copy link
Contributor

rojiphil commented Aug 8, 2024

  • Are you able to test the current API by making a real API request through our web proxy? If not, how do you plan to test? (i.e. Will you need support from an internal engineer?)

We will need the support of an internal engineer to make the BE changes.
With the current changes, the BE returns 666 code response. So, to test until we are BE ready, I have injected some test data in the code which will be removed once the BE is ready. As soon as the BE is ready, the FE should work seamlessly though.

  • Can you please add some detail around what specific changes will need to be made to the BE?

    • The current implementation in the web API essentially proxies the request to https://maps.googleapis.com/maps/api, passing along the query parameters from the front-end after injecting/replacing the api key.
    • Please detail any changes that will be made to the URL, http method, etc. Please ensure this design will remain backwards-compatible. (We either need to add a new proxy endpoint or update the existing one to differentiate between the requests and support both types.)

The specific changes are as follows:

  1. Current implementation proxies the request to https://maps.googleapis.com/maps/api. The new implementation should proxy the request to https://places.googleapis.com for both Autocomplete API (New) and Place Details (New). And, as usual, we need to pass along the query parameters from the FE after injecting/replacing the api key.

  2. I proposed to add new proxy endpoints. That way, our design would be backward-compatible.

For Autocomplete API (New):
HTTP Method: POST
Query URL begins with /v1/places:autocomplete

For Place Details API (New):
HTTP Method: GET
Query URL begins with /v1/places/${rowData.place_id} where rowData.place_id represents the placeId of the place for which details are to be fetched.

  • Please also detail what additional scopes need to be added to the API key, or if a new key is required. If it's possible to add scopes to the existing key rather than generate a new one, I think that would be preferred, as it will simplify the BE code a bit.

The steps required to enable Places API (New) to the API key is mentioned here. I think we can update the existing API key itself if it is going to simplify the BE.

@rafecolton
Copy link
Member Author

Oh I forgot to mention - I made the existing proxy command backwards-compatible, so we won't need a new command/url

@rafecolton rafecolton added Daily KSv2 and removed Weekly KSv2 labels Sep 17, 2024
@rafecolton
Copy link
Member Author

The BE changes were merged and deployed to staging today, so they should be in prod on Monday. We are discussing on the App PR whether or not it will be possible for C/C+ to test on staging.

Copy link

melvin-bot bot commented Sep 23, 2024

@rafecolton, @rojiphil, @Christinadobrzyn, @mkhutornyi Eep! 4 days overdue now. Issues have feelings too...

@melvin-bot melvin-bot bot added the Overdue label Sep 23, 2024
@mkhutornyi
Copy link
Contributor

Not overdue

@Christinadobrzyn
Copy link
Contributor

yes, not overdue Melvin.

@melvin-bot melvin-bot bot removed the Overdue label Sep 23, 2024
@rafecolton
Copy link
Member Author

Saw you pushed some changes @rojiphil and commented on the PRs. I've been swamped today, so I'll try to get to this tomorrow. Making myself the issue owner now since this is waiting on my review.

@Christinadobrzyn
Copy link
Contributor

Just a heads up that I'm going to be travelling for the rest of the week - back on Monday. I'm not going to assign a new BZ teammate since this is being handled at the PR stage.

@rafecolton
Copy link
Member Author

No problem, thanks for the heads up. @rojiphil thanks for your patience, I've been swamped the last couple days. Hope to get back to this ASAP.

@melvin-bot melvin-bot bot added the Overdue label Sep 30, 2024
@rafecolton
Copy link
Member Author

Looking at this now

@melvin-bot melvin-bot bot removed the Overdue label Sep 30, 2024
@rafecolton rafecolton added the Reviewing Has a PR in review label Oct 1, 2024
@rafecolton
Copy link
Member Author

Marking Reviewing as all related PRs are under review currently

@Christinadobrzyn
Copy link
Contributor

With Reviewing, should we move this from daily to weekly?

@rafecolton
Copy link
Member Author

Let's keep it at Daily. In fact, I'll take it out of reviewing and make @rojiphil the issue owner until the final App PR is ready to review.

@rafecolton rafecolton removed the Reviewing Has a PR in review label Oct 2, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Oct 4, 2024
@rafecolton
Copy link
Member Author

Final PR is now up for review! Cool to see that Melvin added the labels automagically ✨

@rafecolton
Copy link
Member Author

PR is failing on android without content-type header, but with the header, it produces a CORS error. I dug into that before when I was testing and it was a rabbit hole, but since it seems to be required here, I'll have to dig more. Setting myself as the issue owner now since this is blocked on me. Might not be able to get back to this until next week, have some higher priority issues assigned currently

@rafecolton
Copy link
Member Author

Thanks for your patience on this @rojiphil - I still plan on getting back to this as soon as I wrap up some other issues

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Nov 21, 2024
Copy link

melvin-bot bot commented Nov 21, 2024

This issue has not been updated in over 15 days. @rafecolton, @rojiphil, @Christinadobrzyn, @mkhutornyi eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@rafecolton
Copy link
Member Author

Sorry to leave this sit for so long. It's still on my radar, just not able to prioritize at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Internal Requires API changes or must be handled by Expensify staff Monthly KSv2 Reviewing Has a PR in review
Projects
No open projects
Status: Polish
Development

No branches or pull requests

6 participants