diff --git a/app/controllers/api/v1/genres_controller.rb b/app/controllers/api/v1/genres_controller.rb new file mode 100644 index 00000000..68939c97 --- /dev/null +++ b/app/controllers/api/v1/genres_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Api::V1::GenresController < ApplicationController + def index + @genres = Genre.published + end +end diff --git a/app/views/api/v1/genres/index.json.jbuilder b/app/views/api/v1/genres/index.json.jbuilder new file mode 100644 index 00000000..3005deca --- /dev/null +++ b/app/views/api/v1/genres/index.json.jbuilder @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +json.array! @genres do |genre| + json.name genre.name + json.slug genre.slug +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 8f63b5b6..5ef5c323 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,8 +41,11 @@ namespace :api do namespace :v1 do - get "new_releases", to: "products#new_releases", as: "new_releases" - get "top_ten", to: "products#top_ten", as: "top_ten" + resources :products do + get "new_releases", to: "products#new_releases", on: :collection + get "top_ten", to: "products#top_ten", on: :collection + end + resources :genres, only: :index end end