All threads / Architecture Question - Connecting google books API and voting on favorite book

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Architecture Question - Connecting google books API and voting on favorite book

Joel Tennant asked in Rails

Hey guys,

I am using the Google books API to pull books and show them on my site. This is working great. However, I want to be able to allow users to favorite books they want to remember and also upvote or downvote books. Normally this would be easy. But the problem is that the books are not in my database, they come from calls to the API.

The problem is, how do I link favorites or votes to a book if books onl come from the api? So I thought that I could implement a function in voting and favoriting that first checks to see if the book is in my database, if it isn't then it adds it immediately then adds the persons vote. This would allow me to only put books in the DB when someone does the first vote or first favorite. However, how do I implement that and is that the best course to take?

Thank you,

I would like to know how to do this as well. I would think that you can just take the data that is returned and run a create method on it to store it into the database. However, some kind of table should exists for that data.

Great idea, I think this format will be very convenient. This is a very useful feature that will really help you find your favorite books faster. Yesterday on the site https://studyhippo.com/essay-examples/lord-of-the-flies/ I read several articles about my favorite book - The Lord of the Rings. I love it, I love the universe of this book and how detailed everything is in it.

Since the books aren't in your database, you'll want to find a way to uniquely identify them, and store entries in your database that correlate to them. Maybe you have a table of Favorites, each row has a user_id, and a book_id that matches the unique id that the API returns. Then you can check this table when displaying them. You could do the same thing for Votes.

I think this is a cool idea.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,130+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.