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

Feature/Browse Books #15

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

Feature/Browse Books #15

wants to merge 11 commits into from

Conversation

beniaminmuresan
Copy link
Contributor

@beniaminmuresan beniaminmuresan commented May 25, 2020

This PR does the following:

  • Create books table with {title, author, isbn, release_year, image_url} attributes
  • Add index action on books controller, add model, route
  • Add fastjson api gem
  • Add pagination mechanism with pagy gem
  • Setup Rspec and add index action spec for BooksController
  • Add books seeds
  • Fix test environment config file

Copy link
Member

@alexandru-calinoiu alexandru-calinoiu left a comment

Choose a reason for hiding this comment

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

Looks good, a couple of small comments.

Gemfile Outdated Show resolved Hide resolved
@@ -1,3 +1,6 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
namespace :v1, format: :jsonapi do
Copy link
Member

Choose a reason for hiding this comment

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

This namespacing with v1 is one way to go about it.

An alternative will be to use custom content-types, have you used that before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're talking about same route responding to both (for example) html and json, right?

Copy link
Member

Choose a reason for hiding this comment

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

no, not really, in the context of jsonapi using links and versioning the api in routes might be tricky.

spec/controllers/books_controller_spec.rb Show resolved Hide resolved
@@ -0,0 +1,6 @@
class V1::BooksController < ApplicationController
def index
@pagy, books = pagy(Book.all)
Copy link
Member

Choose a reason for hiding this comment

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

Marrying a framework will bite you down the line one way or the other. Do you know why / options to limit the impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't exactly know what you mean. Can you be a little more specific, please? Is is the single line assignment or is it the way I declared the BooksController class?

Copy link
Member

Choose a reason for hiding this comment

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

Let's imagine that your application grows over time. You end up at some point with pagy in all controllers. At some point, pagy is no longer supported / has some issues and we want to avoid using it. What do we do? We need to either modify all controllers or implement a pagy method on the application controller.

Copy link
Member

Choose a reason for hiding this comment

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

Nothing to do, just wanted to make a point that dependencies should be as much as possible isolated and not propagated through the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally right about that one. If more that one controller was needed, I would've definitely move it to application controller 👍

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.

3 participants