Skip to content

Commit

Permalink
adds api controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
citin committed Jul 6, 2019
1 parent a953d8e commit 6ea39d7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/api/v1/movies_and_seasons_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::MoviesAndSeasonsController < ApplicationController

# GET /api/v1/movies_and_season
def index
render json: (Movie.all + Season.all).sort_by(&:created_at)
end
end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::MoviesController < ApplicationController

# GET /api/v1/movies
def index
render json: Movie.all.order(:created_at)
end
end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/seasons_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::SeasonsController < ApplicationController

# GET /api/v1/seasons
def index
render json: Season.all.order(:created_at)
end
end
24 changes: 24 additions & 0 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Api::V1::UsersController < ApplicationController

# POST /api/v1/users/:id/purchase
# {
# "content_id": 1,
# "content_type": "Movie",
# "purchase_option":
# {
# "price": 2.99,
# "video_quality": "HD"
# }
# }
def purchase
# build content = params[:content_tipe].classify.find(params[:content_id])
# check if content is not in user's library
# build purchase w/options
# po = PurchaseOption.create(params[:purchase_option])
end

# GET /api/v1/users/:id/purchases
def purchases
render json: User.find(params[:id]).library.sort_by(&:remaining_time)
end
end
14 changes: 13 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
namespace :api do
namespace :v1 do
resources :movies
resources :seasons
resources :movies_and_seasons
resources :users do
member do
post 'purchase'
get 'purchases'
end
end
end
end
end

0 comments on commit 6ea39d7

Please sign in to comment.