File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class Api ::V1 ::ApiController < Api ::ApiController
2-
3- # def index
4- # products = Product.all
5- # render json: { product: products }, status: :ok
6- # end
72
8- before_action :checkToken
3+ before_action :checkToken
94 def productAll
105 products = Product . all
116 render json : { success : true , products : products } , status : 200
127 end
138
9+ before_action :checkToken
10+ def productSingle
11+ product = Product . find ( params [ :id ] )
12+ render json : { success : true , products : [ product ] } , status : 200
13+ end
14+
1415 def checkToken
1516 user = User . find_by ( auth_token : request . headers [ "token" ] )
1617 if user . nil?
17- render json : { } , status : 401
18+ render json : { erros : '401 Unauthorized' } , status : 401
1819 else
1920 return true
2021 end
Original file line number Diff line number Diff line change 1919 end
2020 end
2121
22+ #API REST
2223 namespace :api , format : 'json' do
23- namespace :v1 do
24- post "auth" , to : "auth#create"
25- get "locales" , to : "locales#index" , as : "locales"
26- get "product" , to : "api#productAll"
27- end
28-
29-
24+ namespace :v1 do
25+ post "auth" , to : "auth#create"
26+ get "locales" , to : "locales#index" , as : "locales"
27+
28+
29+ get "product" , to : "api#productAll"
30+ get 'product/:id' , to : "api#productSingle"
31+
32+ end
3033 end
3134
3235end
You can’t perform that action at this time.
0 commit comments