Define endpoint to update expenses #119

Merged
bustikiller merged 1 commits from update-expenses into main 2024-11-11 07:23:40 +00:00
2 changed files with 12 additions and 1 deletions

View File

@ -8,4 +8,15 @@ class ExpensesController < ApplicationController
def index def index
render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type]) render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type])
end end
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
end end

View File

@ -2,7 +2,7 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :groups, only: :index resources :groups, only: :index
resources :guests do resources :guests, only: %i[index update] do
post :bulk_update, on: :collection post :bulk_update, on: :collection
end end
resources :expenses, only: %i[index update] do resources :expenses, only: %i[index update] do