2020-09-04 04:07:43 +03:00
|
|
|
class ChipsController < ApplicationController
|
|
|
|
|
def index
|
2020-10-06 14:17:18 +03:00
|
|
|
all_chips = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
name: 'US Dollar',
|
|
|
|
|
symbol: '$',
|
|
|
|
|
code: 'USD',
|
|
|
|
|
prefixed: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: 'Bosnian Convertible Mark',
|
|
|
|
|
symbol: 'KM',
|
|
|
|
|
code: 'BAM',
|
|
|
|
|
prefixed: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
name: 'Euro',
|
|
|
|
|
symbol: '€',
|
|
|
|
|
code: 'EUR',
|
|
|
|
|
prefixed: false
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
json_response all_chips
|
2020-09-04 04:07:43 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
chip = Chip.new(chip_params)
|
|
|
|
|
if chip.save
|
|
|
|
|
json_response chip
|
|
|
|
|
else
|
|
|
|
|
error_response :bad_request
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
chip_id = params[:id]
|
|
|
|
|
if chip_id.present? && Chip.destroy(chip_id)
|
|
|
|
|
index
|
|
|
|
|
else
|
|
|
|
|
error_response :bad_request
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def chip_params
|
|
|
|
|
params.require(:chip).permit(:id, :name, :symbol, :enabled)
|
|
|
|
|
end
|
|
|
|
|
end
|