From 88a7785b469d13e54c256311373817ad935eb092 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Mon, 11 Nov 2024 08:08:49 +0100 Subject: [PATCH] Define endpoint to update expenses --- app/controllers/expenses_controller.rb | 11 +++++++++++ config/routes.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/expenses_controller.rb b/app/controllers/expenses_controller.rb index 0077568..297fa80 100644 --- a/app/controllers/expenses_controller.rb +++ b/app/controllers/expenses_controller.rb @@ -8,4 +8,15 @@ class ExpensesController < ApplicationController def index render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type]) 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 diff --git a/config/routes.rb b/config/routes.rb index dd8654a..7e40865 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,7 @@ Rails.application.routes.draw do resources :groups, only: :index - resources :guests do + resources :guests, only: %i[index update] do post :bulk_update, on: :collection end resources :expenses, only: %i[index update] do