Manuel Bustillo
6cead51bb9
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m25s
Add copyright notice / copyright_notice (pull_request) Successful in 3m0s
Run unit tests / unit_tests (pull_request) Successful in 4m54s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 45m24s
33 lines
673 B
Ruby
33 lines
673 B
Ruby
# 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.expect(expense: %i[name amount pricing_type])
|
|
end
|
|
end
|