From 5e8aeb928cc73b910460eebdf306da9c23f1f000 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 15 Jun 2020 17:07:28 +0200 Subject: [PATCH] fix refactoring issue in /api/open_api_clients --- .../api/open_api_clients_controller.rb | 28 +++++++++---------- .../open_api_clients/_client.json.jbuilder | 2 ++ .../api/open_api_clients/create.json.jbuilder | 4 ++- .../api/open_api_clients/index.json.jbuilder | 2 +- .../reset_token.json.jbuilder | 2 +- .../api/open_api_clients/update.json.jbuilder | 2 +- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/controllers/api/open_api_clients_controller.rb b/app/controllers/api/open_api_clients_controller.rb index 96f41442e..27edc269f 100644 --- a/app/controllers/api/open_api_clients_controller.rb +++ b/app/controllers/api/open_api_clients_controller.rb @@ -11,35 +11,35 @@ class API::OpenAPIClientsController < API::ApiController end def create - @projets = OpenAPI::Client.new(client_params) - authorize @projets - if @projets.save + @client = OpenAPI::Client.new(client_params) + authorize @client + if @client.save render status: :created else - render json: @projets.errors, status: :unprocessable_entity + render json: @client.errors, status: :unprocessable_entity end end def update - @projets = OpenAPI::Client.find(params[:id]) - authorize @projets - if @projets.update(client_params) + @client = OpenAPI::Client.find(params[:id]) + authorize @client + if @client.update(client_params) render status: :ok else - render json: @projets.errors, status: :unprocessable_entity + render json: @client.errors, status: :unprocessable_entity end end def reset_token - @projets = OpenAPI::Client.find(params[:id]) - authorize @projets - @projets.regenerate_token + @client = OpenAPI::Client.find(params[:id]) + authorize @client + @client.regenerate_token end def destroy - @projets = OpenAPI::Client.find(params[:id]) - authorize @projets - @projets.destroy + @client = OpenAPI::Client.find(params[:id]) + authorize @client + @client.destroy head 204 end diff --git a/app/views/api/open_api_clients/_client.json.jbuilder b/app/views/api/open_api_clients/_client.json.jbuilder index d074fe8cb..9f26bfe35 100644 --- a/app/views/api/open_api_clients/_client.json.jbuilder +++ b/app/views/api/open_api_clients/_client.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.extract! client, :id, :name, :calls_count, :token, :created_at diff --git a/app/views/api/open_api_clients/create.json.jbuilder b/app/views/api/open_api_clients/create.json.jbuilder index 2fb8a1927..0c679a1a4 100644 --- a/app/views/api/open_api_clients/create.json.jbuilder +++ b/app/views/api/open_api_clients/create.json.jbuilder @@ -1 +1,3 @@ -json.partial! 'api/open_api_clients/client', projets: @projets +# frozen_string_literal: true + +json.partial! 'api/open_api_clients/client', client: @client diff --git a/app/views/api/open_api_clients/index.json.jbuilder b/app/views/api/open_api_clients/index.json.jbuilder index 5007e434b..c1b98a76b 100644 --- a/app/views/api/open_api_clients/index.json.jbuilder +++ b/app/views/api/open_api_clients/index.json.jbuilder @@ -1,3 +1,3 @@ json.array! @clients do |client| - json.partial! 'api/open_api_clients/client', projets: client + json.partial! 'api/open_api_clients/client', client: client end diff --git a/app/views/api/open_api_clients/reset_token.json.jbuilder b/app/views/api/open_api_clients/reset_token.json.jbuilder index 2fb8a1927..467fb8a7a 100644 --- a/app/views/api/open_api_clients/reset_token.json.jbuilder +++ b/app/views/api/open_api_clients/reset_token.json.jbuilder @@ -1 +1 @@ -json.partial! 'api/open_api_clients/client', projets: @projets +json.partial! 'api/open_api_clients/client', client: @client diff --git a/app/views/api/open_api_clients/update.json.jbuilder b/app/views/api/open_api_clients/update.json.jbuilder index 2fb8a1927..467fb8a7a 100644 --- a/app/views/api/open_api_clients/update.json.jbuilder +++ b/app/views/api/open_api_clients/update.json.jbuilder @@ -1 +1 @@ -json.partial! 'api/open_api_clients/client', projets: @projets +json.partial! 'api/open_api_clients/client', client: @client