1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/controllers/api/prices_controller.rb

36 lines
773 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for resources of type Price
# Prices are used in reservations (Machine, Space)
2016-03-23 18:39:41 +01:00
class API::PricesController < API::ApiController
before_action :authenticate_user!
def index
@prices = PriceService.list(params)
2016-03-23 18:39:41 +01:00
end
def update
authorize Price
@price = Price.find(params[:id])
price_parameters = price_params
price_parameters[:amount] = price_parameters[:amount] * 100
if @price.update(price_parameters)
2016-03-23 18:39:41 +01:00
render status: :ok
else
render status: :unprocessable_entity
end
end
def compute
cs = CartService.new(current_user)
cart = cs.from_hash(params)
@amount = cart.total
2016-03-23 18:39:41 +01:00
end
private
2016-03-23 18:39:41 +01:00
def price_params
params.require(:price).permit(:amount)
end
end