-
Notifications
You must be signed in to change notification settings - Fork 0
Added support for multiple photos per restaurant #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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,12 +45,23 @@ const getRestaurants = async (zip) => { | |
|
|
||
| return axios | ||
| .get(url) | ||
| .then((res) => { | ||
| .then(async (res) => { | ||
| const { results } = res.data; | ||
|
|
||
| return Promise.allSettled( | ||
| results.map((restaurant) => | ||
| new GoogleRestaurant({ ...restaurant, zip: zip }).save() | ||
| ) | ||
| results.map((restaurant) => { | ||
| const placeDetailsUrl = `https://maps.googleapis.com/maps/api/place/details/json?place_id=${restaurant.place_id}&fields=photo&key=${API_KEY}`; | ||
|
|
||
| return axios.get(placeDetailsUrl) | ||
| .then((res) => { | ||
| const { result } = res.data; | ||
| const photos = result.photos || []; | ||
| // Limit to 10 photos. To remove limit, change to restaurant.photos = photos; | ||
| restaurant.photos = photos.slice(0, 10); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This slicing should go somewhere else. No data received by a Google Places API call should be thrown away. Maybe add it to the part where we create the Restaurant object (rather than GoogleRestaurant)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just remove the slice for now. I'm thinking we save everything but then when we display, we only display like 10.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whenever we do a call to an external API, we want to immediately save the data it returns in as raw of a format as possible to minimize the chance of data loss. So the GoogleRestaurant object shouldn't be touched. Instead, we should add this after we've completed the save of the GoogleRestaurant. Preferably it goes something like this: query google places for restaurants -> immediately turn the result into a GoogleRestaurant object and save -> do the place photos query -> immediately save those into their own object, perhaps call it GoogleRestaurantImage -> finally take the results of all the previous steps and construct a Restaurant object and save that |
||
|
|
||
| return new GoogleRestaurant({ ...restaurant, zip: zip }).save(); | ||
| }); | ||
| }) | ||
| ); | ||
| }) | ||
| .then((restaurantsSettled) => | ||
|
|
@@ -66,6 +77,8 @@ const getRestaurants = async (zip) => { | |
| }); | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| module.exports = { | ||
| getImageTags, | ||
| getRestaurantImages, | ||
|
|
||
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.
Can we factor this out into its own separate function?
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.
Fixed.