=begin Lesli Copyright (c) 2023, Lesli Technologies, S. A. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. Lesli · Ruby on Rails SaaS Development Framework. Made with ♥ by https://www.lesli.tech Building a better future, one line of code at a time. @contact hello@lesli.tech @website https://www.lesli.tech @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ // · =end module LesliGuard class DescriptorsController < ApplicationController before_action :set_descriptor, only: %i[ show update destroy ] # GET /descriptors/list.json def list respond_to do |format| format.html {} format.json do respond_with_successful(DescriptorService.new(current_user, query).list) end end end # GET /descriptors def index respond_to do |format| format.html {} format.json do #respond_with_successful(DescriptorService.new(current_user, query).index) respond_with_pagination(DescriptorService.new(current_user, query).index) end end end # GET /descriptors/:id def show respond_to do |format| format.html {} format.json do respond_with_successful(@descriptor.show) end end end # GET /descriptors/new def new end # GET /descriptors/:id/edit def edit end # POST /descriptors def create descriptor = DescriptorService.new(current_user, query).create(descriptor_params) # Check if the creation went ok if descriptor.successful? respond_with_successful(descriptor) else respond_with_error(descriptor.errors) end end # PATCH/PUT /descriptors/:id def update return respond_with_not_found unless @descriptor.found? @descriptor.update(descriptor_params) # Check if the update went ok unless @descriptor.successful? return respond_with_error(@descriptor.errors) end respond_with_successful(@descriptor.result) end # DELETE /descriptors/1 def destroy return respond_with_not_found unless @descriptor.found? @descriptor.destroy # Check if the deletion went ok unless @descriptor.successful? return respond_with_error(@descriptor.errors) end respond_with_successful end private # Use callbacks to share common setup or constraints between actions. def set_descriptor @descriptor = DescriptorService.new(current_user, @query).find(params[:id]) end # Only allow a list of trusted parameters through. def descriptor_params params.require(:descriptor).permit(:id, :name) end end end