Skip to content

Commit

Permalink
Refractored pipe function
Browse files Browse the repository at this point in the history
  • Loading branch information
MICHAELMUNAVU83 committed Nov 15, 2023
1 parent 9ad48f1 commit 04d166b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/elixir_conf_africa/ticket_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ defmodule ElixirConfAfrica.TicketTypes do
Repo.all(TicketType)
end

def add_quantity(ticket_type, quantity) do
ticket_type
|> Map.put(:quantity, quantity)
end

@doc """
Gets a single ticket_type.
Expand Down
6 changes: 4 additions & 2 deletions lib/elixir_conf_africa_web/live/home_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ defmodule ElixirConfAfricaWeb.HomeLive.Index do

def handle_event("add_to_cart", %{"id" => id}, socket) do
ticket_type =
TicketTypes.get_ticket_type!(String.to_integer(id))
|> Map.put(:quantity, 1)
id
|> String.to_integer()
|> TicketTypes.get_ticket_type!()
|> TicketTypes.add_quantity(1)

if Enum.member?(socket.assigns.cart, ticket_type) do
{:noreply,
Expand Down

0 comments on commit 04d166b

Please sign in to comment.