diff options
| author | mo khan <mo@mokhan.ca> | 2014-11-20 22:18:20 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-11-20 22:18:20 -0700 |
| commit | c752824f9cdf780d0e09cbcb3eabc3bd762e658c (patch) | |
| tree | 52509ccc4e224ec8bf84a36907fe5f0520fbdba8 | |
| parent | a2699047fdf16e8a751f3009458256639d245fd1 (diff) | |
add photos and users to api v2.
| -rw-r--r-- | app/controllers/api/v2/photos_controller.rb | 13 | ||||
| -rw-r--r-- | app/controllers/api/v2/users_controller.rb | 9 | ||||
| -rw-r--r-- | app/views/api/v2/cakes/_cake.json.jbuilder | 2 | ||||
| -rw-r--r-- | app/views/api/v2/cakes/index.json.jbuilder | 3 | ||||
| -rw-r--r-- | app/views/api/v2/photos/_photo.json.jbuilder | 4 | ||||
| -rw-r--r-- | app/views/api/v2/photos/show.json.jbuilder | 3 | ||||
| -rw-r--r-- | app/views/api/v2/users/_user.json.jbuilder | 4 | ||||
| -rw-r--r-- | app/views/api/v2/users/show.json.jbuilder | 3 | ||||
| -rw-r--r-- | config/routes.rb | 2 |
9 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/api/v2/photos_controller.rb b/app/controllers/api/v2/photos_controller.rb new file mode 100644 index 00000000..c4240327 --- /dev/null +++ b/app/controllers/api/v2/photos_controller.rb @@ -0,0 +1,13 @@ +module Api + module V2 + class PhotosController < ApplicationController + def index + @photos = Photo.page(page).per(per_page) + end + + def show(id = params[:id]) + @photo = Photo.find(id) + end + end + end +end diff --git a/app/controllers/api/v2/users_controller.rb b/app/controllers/api/v2/users_controller.rb new file mode 100644 index 00000000..eaa435b4 --- /dev/null +++ b/app/controllers/api/v2/users_controller.rb @@ -0,0 +1,9 @@ +module Api + module V2 + class UsersController < ApplicationController + def show(id = params[:id]) + @user = User.find(id) + end + end + end +end diff --git a/app/views/api/v2/cakes/_cake.json.jbuilder b/app/views/api/v2/cakes/_cake.json.jbuilder index 8ee45c7d..fd8762ae 100644 --- a/app/views/api/v2/cakes/_cake.json.jbuilder +++ b/app/views/api/v2/cakes/_cake.json.jbuilder @@ -1,5 +1,7 @@ json.id cake.id json.name cake.name json.description cake.story +json.author cake.user.id +json.photos cake.photos.pluck(:id) json.createdAt cake.created_at json.updatedAt cake.updated_at diff --git a/app/views/api/v2/cakes/index.json.jbuilder b/app/views/api/v2/cakes/index.json.jbuilder index cf833ae2..9decffb3 100644 --- a/app/views/api/v2/cakes/index.json.jbuilder +++ b/app/views/api/v2/cakes/index.json.jbuilder @@ -3,3 +3,6 @@ json.cakes @cakes do |cake| json.partial! 'cake', cake: cake end end +json.meta do + json.total_pages @cakes.total_pages +end diff --git a/app/views/api/v2/photos/_photo.json.jbuilder b/app/views/api/v2/photos/_photo.json.jbuilder new file mode 100644 index 00000000..4cab3fd3 --- /dev/null +++ b/app/views/api/v2/photos/_photo.json.jbuilder @@ -0,0 +1,4 @@ +json.id photo.id +json.url photo.url_for(:thumb) +json.createdAt photo.created_at +json.updatedAt photo.updated_at diff --git a/app/views/api/v2/photos/show.json.jbuilder b/app/views/api/v2/photos/show.json.jbuilder new file mode 100644 index 00000000..5b7fe738 --- /dev/null +++ b/app/views/api/v2/photos/show.json.jbuilder @@ -0,0 +1,3 @@ +json.photo do + json.partial! @photo, photo: @photo +end diff --git a/app/views/api/v2/users/_user.json.jbuilder b/app/views/api/v2/users/_user.json.jbuilder new file mode 100644 index 00000000..3b153b64 --- /dev/null +++ b/app/views/api/v2/users/_user.json.jbuilder @@ -0,0 +1,4 @@ +json.id user.id +json.name user.name +json.createdAt user.created_at +json.updatedAt user.updated_at diff --git a/app/views/api/v2/users/show.json.jbuilder b/app/views/api/v2/users/show.json.jbuilder new file mode 100644 index 00000000..91ab5f9f --- /dev/null +++ b/app/views/api/v2/users/show.json.jbuilder @@ -0,0 +1,3 @@ +json.user do + json.partial! @user, user: @user +end diff --git a/config/routes.rb b/config/routes.rb index aaff46e9..c61512da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,8 @@ Cake::Application.routes.draw do end namespace :v2 do resources :cakes, only: [:index, :show] + resources :photos, only: [:show] + resources :users, only: [:show] end end |
