1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

fix refactoring issue in /api/open_api_clients

This commit is contained in:
Sylvain 2020-06-15 17:07:28 +02:00
parent b790bc01e7
commit 5e8aeb928c
6 changed files with 22 additions and 18 deletions

View File

@ -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

View File

@ -1 +1,3 @@
# frozen_string_literal: true
json.extract! client, :id, :name, :calls_count, :token, :created_at

View File

@ -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

View File

@ -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

View File

@ -1 +1 @@
json.partial! 'api/open_api_clients/client', projets: @projets
json.partial! 'api/open_api_clients/client', client: @client

View File

@ -1 +1 @@
json.partial! 'api/open_api_clients/client', projets: @projets
json.partial! 'api/open_api_clients/client', client: @client