Remove HTML views and non-JSON endpoints #81
@ -1,76 +1,7 @@
|
|||||||
# Copyright (C) 2024 Manuel Bustillo
|
# Copyright (C) 2024 Manuel Bustillo
|
||||||
|
|
||||||
class ExpensesController < ApplicationController
|
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
|
def summary
|
||||||
render json: Expenses::TotalQuery.new.call
|
render json: Expenses::TotalQuery.new.call
|
||||||
end
|
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
|
end
|
||||||
|
@ -3,64 +3,12 @@
|
|||||||
require 'csv'
|
require 'csv'
|
||||||
|
|
||||||
class GuestsController < ApplicationController
|
class GuestsController < ApplicationController
|
||||||
before_action :set_guest, only: %i[show edit update destroy]
|
|
||||||
|
|
||||||
# GET /guests or /guests.json
|
|
||||||
def index
|
def index
|
||||||
@guests = Guest.all
|
@guests = Guest.all.includes(:group)
|
||||||
.joins(:group)
|
.joins(:group)
|
||||||
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
|
.order('groups.name' => :asc, first_name: :asc, last_name: :asc)
|
||||||
|
|
||||||
render jsonapi: @guests
|
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def import
|
def import
|
||||||
@ -81,16 +29,4 @@ class GuestsController < ApplicationController
|
|||||||
Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status))
|
Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status))
|
||||||
render json: {}, status: :ok
|
render json: {}, status: :ok
|
||||||
end
|
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
|
end
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
class TablesArrangementsController < ApplicationController
|
class TablesArrangementsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@tables_arrangements = TablesArrangement.all.order(discomfort: :asc).limit(10)
|
render json: TablesArrangement.all.order(discomfort: :asc).limit(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@tables_arrangement = TablesArrangement.find(params[:id])
|
render json: TablesArrangement.find(params[:id])
|
||||||
@seats = @tables_arrangement.seats
|
|
||||||
.includes(guest: %i[affinity_groups unbreakable_bonds])
|
|
||||||
.group_by(&:table_number)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<div id="<%= dom_id expense %>">
|
|
||||||
<p>
|
|
||||||
<strong>Name:</strong>
|
|
||||||
<%= expense.name %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Amount:</strong>
|
|
||||||
<%= expense.amount %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Pricing type:</strong>
|
|
||||||
<%= expense.pricing_type %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,34 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<%= form_with(model: expense) do |form| %>
|
|
||||||
<% if expense.errors.any? %>
|
|
||||||
<div style="color: red">
|
|
||||||
<h2><%= pluralize(expense.errors.count, "error") %> prohibited this expense from being saved:</h2>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<% expense.errors.each do |error| %>
|
|
||||||
<li><%= error.full_message %></li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :name, style: "display: block" %>
|
|
||||||
<%= form.text_field :name %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :amount, style: "display: block" %>
|
|
||||||
<%= form.text_field :amount %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :pricing_type, style: "display: block" %>
|
|
||||||
<%= form.text_field :pricing_type %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.submit %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
@ -1,12 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>Editing expense</h1>
|
|
||||||
|
|
||||||
<%= render "form", expense: @expense %>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Show this expense", @expense %> |
|
|
||||||
<%= link_to "Back to expenses", expenses_path %>
|
|
||||||
</div>
|
|
@ -1,30 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<p style="color: green"><%= notice %></p>
|
|
||||||
|
|
||||||
<h1>Expenses</h1>
|
|
||||||
|
|
||||||
<div id="expenses">
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Amount</th>
|
|
||||||
<th colspan="2"></th>
|
|
||||||
</tr>
|
|
||||||
<% @expenses.each do |expense| %>
|
|
||||||
<tr>
|
|
||||||
<td><%= expense.name %></td>
|
|
||||||
<td><%= expense.amount.to_currency %></td>
|
|
||||||
<td><%= link_to "Show", expense %></td>
|
|
||||||
<td><%= link_to "Edit", edit_expense_path(expense) %></td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
<tr>
|
|
||||||
<td>Total</td>
|
|
||||||
<td><%= @expenses.sum(&:amount).to_currency %></td>
|
|
||||||
<td colspan="2"></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= link_to "New expense", new_expense_path %>
|
|
@ -1,11 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>New expense</h1>
|
|
||||||
|
|
||||||
<%= render "form", expense: @expense %>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Back to expenses", expenses_path %>
|
|
||||||
</div>
|
|
@ -1,12 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<p style="color: green"><%= notice %></p>
|
|
||||||
|
|
||||||
<%= render @expense %>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Edit this expense", edit_expense_path(@expense) %> |
|
|
||||||
<%= link_to "Back to expenses", expenses_path %>
|
|
||||||
|
|
||||||
<%= button_to "Destroy this expense", @expense, method: :delete %>
|
|
||||||
</div>
|
|
@ -1,39 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<%= form_with(model: guest) do |form| %>
|
|
||||||
<% if guest.errors.any? %>
|
|
||||||
<div style="color: red">
|
|
||||||
<h2><%= pluralize(guest.errors.count, "error") %> prohibited this guest from being saved:</h2>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<% guest.errors.each do |error| %>
|
|
||||||
<li><%= error.full_message %></li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :first_name, style: "display: block" %>
|
|
||||||
<%= form.text_field :first_name %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :last_name, style: "display: block" %>
|
|
||||||
<%= form.text_field :last_name %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :email, style: "display: block" %>
|
|
||||||
<%= form.text_field :email %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.label :phone, style: "display: block" %>
|
|
||||||
<%= form.text_field :phone %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= form.submit %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
@ -1,24 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<div id="<%= dom_id guest %>">
|
|
||||||
<p>
|
|
||||||
<strong>First name:</strong>
|
|
||||||
<%= guest.first_name %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Last name:</strong>
|
|
||||||
<%= guest.last_name %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Email:</strong>
|
|
||||||
<%= guest.email %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Phone:</strong>
|
|
||||||
<%= guest.phone %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,12 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>Editing guest</h1>
|
|
||||||
|
|
||||||
<%= render "form", guest: @guest %>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Show this guest", @guest %> |
|
|
||||||
<%= link_to "Back to guests", guests_path %>
|
|
||||||
</div>
|
|
@ -1,39 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<p style="color: green"><%= notice %></p>
|
|
||||||
|
|
||||||
<h1>Guests</h1>
|
|
||||||
|
|
||||||
<div id="guests">
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<th>Row #</th>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Email</th>
|
|
||||||
<th>Phone</th>
|
|
||||||
<th>Affinity groups</th>
|
|
||||||
<th>Unbreakable bonds</th>
|
|
||||||
<th colspan="2"></th>
|
|
||||||
</tr>
|
|
||||||
<% @guests.each_with_index do |guest, i| %>
|
|
||||||
<tr>
|
|
||||||
<td><%= i + 1 %></td>
|
|
||||||
<td><%= guest.full_name %></td>
|
|
||||||
<td><%= guest.email %></td>
|
|
||||||
<td><%= guest.phone %></td>
|
|
||||||
<td><%= guest.affinity_groups.pluck(:name).join(", ") %></td>
|
|
||||||
<td><%= guest.unbreakable_bonds.pluck(:name).join(", ") %></td>
|
|
||||||
<td><%= link_to "Show", guest %></td>
|
|
||||||
<td><%= link_to "Edit", edit_guest_path(guest) %></td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<%= link_to "New guest", new_guest_path %>
|
|
||||||
|
|
||||||
<%= form_with url: import_guests_path, method: :post do |form| %>
|
|
||||||
<%= form.label :file %>
|
|
||||||
<%= form.file_field :file %>
|
|
||||||
<%= form.submit "Import" %>
|
|
||||||
<% end %>
|
|
@ -1,11 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>New guest</h1>
|
|
||||||
|
|
||||||
<%= render "form", guest: @guest %>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Back to guests", guests_path %>
|
|
||||||
</div>
|
|
@ -1,12 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<p style="color: green"><%= notice %></p>
|
|
||||||
|
|
||||||
<%= render @guest %>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<%= link_to "Edit this guest", edit_guest_path(@guest) %> |
|
|
||||||
<%= link_to "Back to guests", guests_path %>
|
|
||||||
|
|
||||||
<%= button_to "Destroy this guest", @guest, method: :delete %>
|
|
||||||
</div>
|
|
@ -1,18 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>WeddingPlanner</title>
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
||||||
<%= csrf_meta_tags %>
|
|
||||||
<%= csp_meta_tag %>
|
|
||||||
|
|
||||||
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
|
||||||
<%= javascript_importmap_tags %>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<%= yield %>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,11 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>Tables arrangements</h1>
|
|
||||||
|
|
||||||
<ol>
|
|
||||||
<% @tables_arrangements.each_with_index do |tables_arrangement, i| %>
|
|
||||||
<li>
|
|
||||||
<p><%= link_to "Arrangement ##{i+1}", tables_arrangement_path(tables_arrangement) %> Discomfort: <%= tables_arrangement.discomfort %></p>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ol>
|
|
@ -1,18 +0,0 @@
|
|||||||
<%# Copyright (C) 2024 Manuel Bustillo %>
|
|
||||||
|
|
||||||
<h1>ID: <%= @tables_arrangement.id %></h1>
|
|
||||||
|
|
||||||
<p>Discomfort: <%= @tables_arrangement.discomfort %></p>
|
|
||||||
|
|
||||||
<h2>Seats</h2>
|
|
||||||
|
|
||||||
<% @seats.each do |table_number, seats| %>
|
|
||||||
|
|
||||||
<h3>Table <%= table_number %></h3>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<% seats.each do |seat| %>
|
|
||||||
<li><%= seat.guest.full_name %> (<%= seat.guest.affinity_groups.pluck(:name).join(", ") %>)</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
|
Loading…
x
Reference in New Issue
Block a user