Remove HTML views and non-JSON endpoints #81
@ -1,76 +1,7 @@
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
class ExpensesController < ApplicationController
|
||||
before_action :set_expense, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /expenses or /expenses.json
|
||||
def index
|
||||
@expenses = Expense.all
|
||||
end
|
||||
|
||||
def summary
|
||||
render json: Expenses::TotalQuery.new.call
|
||||
end
|
||||
|
||||
# GET /expenses/1 or /expenses/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /expenses/new
|
||||
def new
|
||||
@expense = Expense.new
|
||||
end
|
||||
|
||||
# GET /expenses/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /expenses or /expenses.json
|
||||
def create
|
||||
@expense = Expense.new(expense_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @expense.save
|
||||
format.html { redirect_to expense_url(@expense), notice: "Expense was successfully created." }
|
||||
format.json { render :show, status: :created, location: @expense }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @expense.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /expenses/1 or /expenses/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @expense.update(expense_params)
|
||||
format.html { redirect_to expense_url(@expense), notice: "Expense was successfully updated." }
|
||||
format.json { render :show, status: :ok, location: @expense }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @expense.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /expenses/1 or /expenses/1.json
|
||||
def destroy
|
||||
@expense.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to expenses_url, notice: "Expense was successfully destroyed." }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_expense
|
||||
@expense = Expense.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def expense_params
|
||||
params.require(:expense).permit(:name, :amount, :pricing_type)
|
||||
end
|
||||
end
|
||||
|
@ -3,64 +3,12 @@
|
||||
require 'csv'
|
||||
|
||||
class GuestsController < ApplicationController
|
||||
before_action :set_guest, only: %i[show edit update destroy]
|
||||
|
||||
# GET /guests or /guests.json
|
||||
def index
|
||||
@guests = Guest.all
|
||||
@guests = Guest.all.includes(:group)
|
||||
.joins(:group)
|
||||
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
|
||||
|
||||
render jsonapi: @guests
|
||||
end
|
||||
|
||||
# GET /guests/1 or /guests/1.json
|
||||
def show; end
|
||||
|
||||
# GET /guests/new
|
||||
def new
|
||||
@guest = Guest.new
|
||||
end
|
||||
|
||||
# GET /guests/1/edit
|
||||
def edit; end
|
||||
|
||||
# POST /guests or /guests.json
|
||||
def create
|
||||
@guest = Guest.new(guest_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @guest.save
|
||||
format.html { redirect_to guest_url(@guest), notice: 'Guest was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @guest }
|
||||
else
|
||||
format.html { render :new, status: :unprocessable_entity }
|
||||
format.json { render json: @guest.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /guests/1 or /guests/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @guest.update(guest_params)
|
||||
format.html { redirect_to guest_url(@guest), notice: 'Guest was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @guest }
|
||||
else
|
||||
format.html { render :edit, status: :unprocessable_entity }
|
||||
format.json { render json: @guest.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /guests/1 or /guests/1.json
|
||||
def destroy
|
||||
@guest.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to guests_url, notice: 'Guest was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
render jsonapi: @guests
|
||||
end
|
||||
|
||||
def import
|
||||
@ -81,16 +29,4 @@ class GuestsController < ApplicationController
|
||||
Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status))
|
||||
render json: {}, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_guest
|
||||
@guest = Guest.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def guest_params
|
||||
params.require(:guest).permit(:first_name, :last_name, :email, :phone)
|
||||
end
|
||||
end
|
||||
|
@ -2,13 +2,10 @@
|
||||
|
||||
class TablesArrangementsController < ApplicationController
|
||||
def index
|
||||
@tables_arrangements = TablesArrangement.all.order(discomfort: :asc).limit(10)
|
||||
render json: TablesArrangement.all.order(discomfort: :asc).limit(10)
|
||||
end
|
||||
|
||||
def show
|
||||
@tables_arrangement = TablesArrangement.find(params[:id])
|
||||
@seats = @tables_arrangement.seats
|
||||
.includes(guest: %i[affinity_groups unbreakable_bonds])
|
||||
.group_by(&:table_number)
|
||||
render json: TablesArrangement.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user