Skip to content

Added support for multiple photos per restaurant#3

Open
gnehzza wants to merge 1 commit intomainfrom
gnehzza/get_multiple_images
Open

Added support for multiple photos per restaurant#3
gnehzza wants to merge 1 commit intomainfrom
gnehzza/get_multiple_images

Conversation

@gnehzza
Copy link
Copy Markdown
Collaborator

@gnehzza gnehzza commented Jun 7, 2023

No description provided.

@gnehzza gnehzza requested a review from codercody June 7, 2023 13:09
return axios
.get(url)
.then((res) => {
.then(async (res) => {
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

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.

2 participants