From 810d0740f3babc3c3df51a085583002e1e291ee6 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 20:40:37 +0100 Subject: [PATCH] Define an endpoint to expose the list of expenses --- app/controllers/expenses_controller.rb | 4 ++++ config/routes.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/expenses_controller.rb b/app/controllers/expenses_controller.rb index e208a12..0077568 100644 --- a/app/controllers/expenses_controller.rb +++ b/app/controllers/expenses_controller.rb @@ -4,4 +4,8 @@ class ExpensesController < ApplicationController def summary render json: Expenses::TotalQuery.new.call end + + def index + render json: Expense.all.order(pricing_type: :asc, amount: :desc).as_json(only: %i[id name amount pricing_type]) + end end diff --git a/config/routes.rb b/config/routes.rb index a7b4d0c..df17dac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ Rails.application.routes.draw do post :import, on: :collection post :bulk_update, on: :collection end - resources :expenses do + resources :expenses, only: :index do get :summary, on: :collection end resources :tables_arrangements, only: [:index, :show]