I have been learning Elixir lately and am wondering what is the correct syntax for solving my current issue. I am trying to update a model using Elixir and this update includes adding a value to the current value (ie amount = amount + passed_amount) and pushing a new value to an ecto array (ie transactions ++ new_transaction). Here is my latest attempt at doing this:
def add_transaction(conn, %{"coin" => coin_params}) do
coin = Repo.get_by!(WalletCoin, ticker: coin_params["ticker"])
coin["transactions"] ++ coin_params["transaction"]
coin["amount"] = coin["amount"] + coin_params["amount"]
case Repo.update(coin) do
{ok, _coin} ->
coins = Repo.all(WalletCoin)
render conn, "index.json", coins: coins
end
end
My intentions of asking this question was to get the answer and hopefully get some insight into Elixir best practices for doing this.
Thanks in advance