mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Account namespace updates: part 5 (valuations) (#901)
* Move Valuation to Account namespace * Move account history to controller * Clean up valuation controller and views * Translations and cleanup * Remove unused scopes and methods * Pass brakeman
This commit is contained in:
parent
0bc0d87768
commit
12380dc8ad
45 changed files with 478 additions and 346 deletions
61
app/controllers/account/valuations_controller.rb
Normal file
61
app/controllers/account/valuations_controller.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
class Account::ValuationsController < ApplicationController
|
||||
before_action :set_account
|
||||
before_action :set_valuation, only: %i[ show edit update destroy ]
|
||||
|
||||
def new
|
||||
@valuation = @account.valuations.new
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
@valuation = @account.valuations.build(valuation_params)
|
||||
|
||||
if @valuation.save
|
||||
@valuation.sync_account_later
|
||||
redirect_to account_path(@account), notice: "Valuation created"
|
||||
else
|
||||
# TODO: this is not an ideal way to handle errors and should eventually be improved.
|
||||
# See: https://github.com/hotwired/turbo-rails/pull/367
|
||||
flash[:error] = @valuation.errors.full_messages.to_sentence
|
||||
redirect_to account_path(@account)
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @valuation.update(valuation_params)
|
||||
@valuation.sync_account_later
|
||||
redirect_to account_path(@account), notice: t(".success")
|
||||
else
|
||||
# TODO: this is not an ideal way to handle errors and should eventually be improved.
|
||||
# See: https://github.com/hotwired/turbo-rails/pull/367
|
||||
flash[:error] = @valuation.errors.full_messages.to_sentence
|
||||
redirect_to account_path(@account)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@valuation.destroy!
|
||||
@valuation.sync_account_later
|
||||
|
||||
redirect_to account_path(@account), notice: t(".success")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = Current.family.accounts.find(params[:account_id])
|
||||
end
|
||||
|
||||
def set_valuation
|
||||
@valuation = @account.valuations.find(params[:id])
|
||||
end
|
||||
|
||||
def valuation_params
|
||||
params.require(:account_valuation).permit(:date, :value, :currency)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue