Merge pull request 'Define and document CRUD endpoints for expenses' (#180) from expenses-crud into main
Reviewed-on: #180
This commit is contained in:
commit
71eecf94a6
@ -9,11 +9,21 @@ class ExpensesController < ApplicationController
|
||||
render json: Expense.all.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
|
||||
|
@ -27,7 +27,7 @@ Rails.application.routes.draw do
|
||||
resources :guests, only: %i[index create update destroy] do
|
||||
post :bulk_update, on: :collection
|
||||
end
|
||||
resources :expenses, only: %i[index update] do
|
||||
resources :expenses, only: %i[index create update destroy] do
|
||||
get :summary, on: :collection
|
||||
end
|
||||
resources :tables_arrangements, only: %i[index show]
|
||||
|
@ -16,9 +16,7 @@ RSpec.describe 'expenses', type: :request do
|
||||
required: %i[id name amount pricing_type],
|
||||
properties: {
|
||||
id: { type: :string, format: :uuid },
|
||||
name: { type: :string },
|
||||
amount: { type: :number },
|
||||
pricing_type: { type: :string, enum: Expense.pricing_types.keys }
|
||||
**Swagger::Schema::EXPENSE
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,10 +24,31 @@ RSpec.describe 'expenses', type: :request do
|
||||
end
|
||||
regular_api_responses
|
||||
end
|
||||
|
||||
post 'create expense' do
|
||||
tags 'Expenses'
|
||||
consumes 'application/json'
|
||||
produces 'application/json'
|
||||
parameter Swagger::Schema::SLUG
|
||||
parameter name: :body, in: :body, schema: {
|
||||
type: :object,
|
||||
required: %i[expense],
|
||||
properties: {
|
||||
expense: {
|
||||
type: :object,
|
||||
required: %i[name amount pricing_type],
|
||||
properties: Swagger::Schema::EXPENSE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response_empty_201
|
||||
response_422
|
||||
regular_api_responses
|
||||
end
|
||||
end
|
||||
|
||||
path '/{slug}/expenses/{id}' do
|
||||
|
||||
patch('update expense') do
|
||||
tags 'Expenses'
|
||||
consumes 'application/json'
|
||||
@ -38,11 +57,7 @@ RSpec.describe 'expenses', type: :request do
|
||||
parameter name: 'id', in: :path, type: :string, format: :uuid, description: 'id'
|
||||
parameter name: :body, in: :body, schema: {
|
||||
type: :object,
|
||||
properties: {
|
||||
name: { type: :string },
|
||||
amount: { type: :number, minimum: 0 },
|
||||
pricing_type: { type: :string, enum: Expense.pricing_types.keys }
|
||||
}
|
||||
properties: Swagger::Schema::EXPENSE
|
||||
}
|
||||
|
||||
response_empty_200
|
||||
@ -50,5 +65,15 @@ RSpec.describe 'expenses', type: :request do
|
||||
response_404
|
||||
regular_api_responses
|
||||
end
|
||||
|
||||
delete('delete expense') do
|
||||
tags 'Expenses'
|
||||
produces 'application/json'
|
||||
parameter Swagger::Schema::SLUG
|
||||
parameter Swagger::Schema::ID
|
||||
response_empty_200
|
||||
response_404
|
||||
regular_api_responses
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -23,6 +23,12 @@ module Swagger
|
||||
color: { type: :string, pattern: '^#(?:[0-9a-fA-F]{3}){1,2}$' }
|
||||
}
|
||||
|
||||
EXPENSE = {
|
||||
name: { type: :string },
|
||||
amount: { type: :number, minimum: 0 },
|
||||
pricing_type: { type: :string, enum: Expense.pricing_types.keys }
|
||||
}
|
||||
|
||||
SLUG = {
|
||||
name: 'slug',
|
||||
in: :path,
|
||||
|
Loading…
x
Reference in New Issue
Block a user