wedding-planner/app/controllers/expenses_controller.rb

35 lines
721 B
Ruby

# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo
class ExpensesController < ApplicationController
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
def create
Expense.create!(expense_params)
render json: {}, status: :created
end
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
private
def expense_params
params.require(:expense).permit(:name, :amount, :pricing_type)
end
end