Skip to content

Commit

Permalink
refactor: make use of helper functions in Arrow.Shuttles for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Nov 6, 2024
1 parent 7577fc4 commit bfb4fd6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/arrow/shuttles/shuttle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ defmodule Arrow.Shuttles.Shuttle do
field :shuttle_name, :string
field :disrupted_route_id, :string

has_many :routes, Arrow.Shuttles.Route,
preload_order: [asc: :direction_id],
on_replace: :delete
has_many :routes, Arrow.Shuttles.Route, preload_order: [asc: :direction_id]

timestamps(type: :utc_datetime)
end
Expand Down
7 changes: 2 additions & 5 deletions lib/arrow_web/live/shuttle_live/shuttle_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ defmodule ArrowWeb.ShuttleViewLive do

def handle_event("edit", %{"shuttle_route" => shuttle_route_params}, socket) do
shuttle = Shuttles.get_shuttle!(socket.assigns.shuttle_route.id)
changeset = Shuttles.change_shuttle(shuttle, shuttle_route_params)

case Arrow.Repo.update(changeset) do
case Arrow.Shuttles.update_shuttle(shuttle, shuttle_route_params) do
{:ok, shuttle} ->
{:noreply,
socket
Expand All @@ -179,9 +178,7 @@ defmodule ArrowWeb.ShuttleViewLive do
end

def handle_event("create", %{"shuttle_route" => shuttle_route_params}, socket) do
changeset = Shuttles.change_shuttle(%Shuttle{}, shuttle_route_params)

case Arrow.Repo.insert(changeset) do
case Arrow.Shuttles.create_shuttle(shuttle_route_params) do
{:ok, shuttle} ->
{:noreply,
socket
Expand Down

0 comments on commit bfb4fd6

Please sign in to comment.