mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
72 lines
2 KiB
Ruby
72 lines
2 KiB
Ruby
class TransfersController < ApplicationController
|
|
before_action :set_transfer, only: %i[destroy show update]
|
|
|
|
def new
|
|
@transfer = Transfer.new
|
|
end
|
|
|
|
def show
|
|
@categories = Current.family.categories.expenses
|
|
end
|
|
|
|
def create
|
|
from_account = Current.family.accounts.find(transfer_params[:from_account_id])
|
|
to_account = Current.family.accounts.find(transfer_params[:to_account_id])
|
|
|
|
@transfer = Transfer.from_accounts(
|
|
from_account: from_account,
|
|
to_account: to_account,
|
|
date: transfer_params[:date],
|
|
amount: transfer_params[:amount].to_d
|
|
)
|
|
|
|
if @transfer.save
|
|
@transfer.sync_account_later
|
|
|
|
flash[:notice] = t(".success")
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to transactions_path }
|
|
redirect_target_url = request.referer || transactions_path
|
|
format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
|
|
end
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
if transfer_update_params[:status] == "rejected"
|
|
@transfer.reject!
|
|
elsif transfer_update_params[:status] == "confirmed"
|
|
@transfer.confirm!
|
|
end
|
|
|
|
@transfer.outflow_transaction.update!(category_id: transfer_update_params[:category_id])
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_back_or_to transactions_url, notice: t(".success") }
|
|
format.turbo_stream
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@transfer.destroy!
|
|
redirect_back_or_to transactions_url, notice: t(".success")
|
|
end
|
|
|
|
private
|
|
def set_transfer
|
|
@transfer = Transfer.find(params[:id])
|
|
|
|
raise ActiveRecord::RecordNotFound unless @transfer.belongs_to_family?(Current.family)
|
|
end
|
|
|
|
def transfer_params
|
|
params.require(:transfer).permit(:from_account_id, :to_account_id, :amount, :date, :name, :excluded)
|
|
end
|
|
|
|
def transfer_update_params
|
|
params.require(:transfer).permit(:notes, :status, :category_id)
|
|
end
|
|
end
|