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