wedding-planner/app/controllers/expenses_controller.rb

35 lines
743 B
Ruby
Raw Normal View History

# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
2024-10-27 21:42:45 +00:00
# frozen_string_literal: true
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
def index
render json: Expense.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 create
Expense.create!(expense_params)
render json: {}, status: :created
end
2024-11-11 08:08:49 +01:00
def update
Expense.find(params[:id]).update!(expense_params)
render json: {}, status: :ok
end
def destroy
Expense.find(params[:id]).destroy!
render json: {}, status: :ok
end
2024-11-11 08:08:49 +01:00
private
def expense_params
params.require(:expense).permit(:name, :amount, :pricing_type)
end
2024-07-11 19:55:48 +02:00
end