wedding-planner/app/controllers/expenses_controller.rb
Manuel Bustillo 91bbae1c63
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 59s
Add copyright notice / copyright_notice (pull_request) Successful in 2m21s
Run unit tests / unit_tests (pull_request) Successful in 3m2s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 25m17s
Add copyright notice
2025-01-13 20:38:47 +00:00

37 lines
781 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
# frozen_string_literal: true
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