# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre # Departamento de Informatica - Universidade Federal do Parana # # This file is part of portalmec. # # portalmec is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # portalmec is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with portalmec. If not, see <http://www.gnu.org/licenses/>. class V1::ScoresController < ApplicationController include ::Paginator before_action :authenticate_user!, only: [:update] before_action :set_score, only: [:show, :update] before_action :authorize!, only: [:update] # GET v1/scores # GET v1/scores.json def index params[:sort] = '["name","ASC"]' if params[:sort].blank? scores = paginate Score render json: scores end # GET /scores/1 # GET /scores/1.json def show render json: @score, status: :ok end # PUT/PATCH /v1/scores/1 # PUT/PATCH /v1/scores/1.json def update if @score.update(score_params) render json: @score, status: :ok, :notice => "Score updated." else render json: @score.errors, status: :unprocessable_entity end end private def set_score @score = Score.find params[:id] end def score_params params.require(:score).permit(:name, :weight, :active, score_type: []) end def authorize! authorize @score end end