Newer
Older

Israel Barreto Sant'Anna
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class V1::RatingsController < ApplicationController
include ::DeletedObjectsController
before_action :set_rating, only: [:show, :update, :destroy]
before_action :authenticate_user!, only: [:create, :update, :destroy]
# GET v1/ratings
# GET v1/ratings.json
def index
render json: Rating.all
end
# GET v1/ratings/1
# GET v1/ratings/1.json
def show
render json: @rating
end
# POST v1/ratings
# POST v1/ratings.json
def create
rating = Rating.new(rating_params)
if rating.save
render json: rating, status: :created
else
render json: rating.errors, status: :unprocessable_entity
end
end
# PUT/PATCH /v1/ratings/1
# PUT/PATCH /v1/ratings/1.json
def update
if @rating.update(rating_params)
render json: @rating, status: :ok
else
render json: @rating.errors, status: :unprocessable_entity
end
end
# DELETE v1/ratings/1
# DELETE v1/ratings/1.json
def destroy
@rating.destroy
render nothing: true, status: :ok
end
private
def deleted_resource
Rating
end
def set_rating
@rating = Rating.find(params[:id])
end
def rating_params
params.require(:rating).permit(:name, :description)
end
end