2024-10-27 21:42:45 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2024-07-11 19:55:48 +02:00
|
|
|
class ExpensesController < ApplicationController
|
2024-10-28 23:01:46 +01:00
|
|
|
def summary
|
|
|
|
render json: Expenses::TotalQuery.new.call
|
|
|
|
end
|
2024-11-10 20:40:37 +01:00
|
|
|
|
|
|
|
def index
|
|
|
|
render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type])
|
|
|
|
end
|
2024-11-11 08:08:49 +01:00
|
|
|
|
|
|
|
def update
|
|
|
|
Expense.find(params[:id]).update!(expense_params)
|
|
|
|
render json: {}, status: :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def expense_params
|
|
|
|
params.require(:expense).permit(:name, :amount, :pricing_type)
|
|
|
|
end
|
2024-07-11 19:55:48 +02:00
|
|
|
end
|