Skip to content

Commit 90bafbb

Browse files
author
Brice MICHALSKI
committed
update body for 401
1 parent 82f9e7e commit 90bafbb

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

app/controllers/api/v1/api_controller.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
class 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

config/routes.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
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

3235
end

0 commit comments

Comments
 (0)