2024-11-27 16:01:50 -05:00
|
|
|
module EntryableResource
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2025-04-14 11:40:34 -04:00
|
|
|
include StreamExtensions, ActionView::RecordIdentifier
|
2024-11-27 16:01:50 -05:00
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
before_action :set_entry, only: %i[show update destroy]
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
account = Current.family.accounts.find_by(id: params[:account_id])
|
|
|
|
|
|
|
|
@entry = Current.family.entries.new(
|
|
|
|
account: account,
|
|
|
|
currency: account ? account.currency : Current.family.currency,
|
2025-04-14 11:40:34 -04:00
|
|
|
entryable: entryable
|
2024-11-27 16:01:50 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2025-04-14 11:40:34 -04:00
|
|
|
raise NotImplementedError, "Entryable resources must implement #create"
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2025-04-14 11:40:34 -04:00
|
|
|
raise NotImplementedError, "Entryable resources must implement #update"
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
account = @entry.account
|
|
|
|
@entry.destroy!
|
|
|
|
@entry.sync_account_later
|
|
|
|
|
2025-04-14 11:40:34 -04:00
|
|
|
redirect_back_or_to account_path(account), notice: t("account.entries.destroy.success")
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2025-04-14 11:40:34 -04:00
|
|
|
def entryable
|
|
|
|
controller_name.classify.constantize.new
|
2024-11-27 16:01:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_entry
|
|
|
|
@entry = Current.family.entries.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|