2024-07-01 10:49:43 -04:00
|
|
|
class Account::EntriesController < ApplicationController
|
2024-07-26 18:00:41 +02:00
|
|
|
layout :with_sidebar
|
2024-07-01 10:49:43 -04:00
|
|
|
|
|
|
|
before_action :set_account
|
2024-08-23 10:06:24 -04:00
|
|
|
before_action :set_entry, only: %i[edit update show destroy]
|
2024-07-01 10:49:43 -04:00
|
|
|
|
|
|
|
def edit
|
2024-08-09 11:22:57 -04:00
|
|
|
render entryable_view_path(:edit)
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2024-08-09 11:22:57 -04:00
|
|
|
@entry.update!(entry_params)
|
2024-07-01 10:49:43 -04:00
|
|
|
@entry.sync_account_later
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to account_entry_path(@account, @entry), notice: t(".success") }
|
|
|
|
format.turbo_stream { render turbo_stream: turbo_stream.replace(@entry) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2024-08-09 11:22:57 -04:00
|
|
|
render entryable_view_path(:show)
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@entry.destroy!
|
|
|
|
@entry.sync_account_later
|
2024-10-09 14:59:18 -04:00
|
|
|
redirect_to account_url(@entry.account), notice: t(".success")
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-08-09 11:22:57 -04:00
|
|
|
def entryable_view_path(action)
|
|
|
|
@entry.entryable_type.underscore.pluralize + "/" + action.to_s
|
|
|
|
end
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
def set_account
|
|
|
|
@account = Current.family.accounts.find(params[:account_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_entry
|
|
|
|
@entry = @account.entries.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def entry_params
|
2024-08-09 11:22:57 -04:00
|
|
|
params.require(:account_entry).permit(:name, :date, :amount, :currency)
|
2024-07-01 10:49:43 -04:00
|
|
|
end
|
|
|
|
end
|