-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ca0e7c
commit ed0341c
Showing
21 changed files
with
275 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Munch.Importer do | ||
use Oban.Worker, queue: :fresh_restaurants | ||
|
||
alias Munch.Restaurants | ||
|
||
@impl Oban.Worker | ||
def perform(%Oban.Job{args: %{"osm_type" => osm_type, "osm_id" => osm_id}}) do | ||
{:ok, restaurant} = Munch.Osm.nominatim_get_details(osm_type, osm_id) | ||
Restaurants.create_restaurant(restaurant) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
defmodule MunchWeb.RestaurantLive.Import do | ||
use MunchWeb, :live_view | ||
|
||
alias Munch.Osm | ||
alias Munch.Restaurants | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<.header> | ||
Add a new restaurant by search | ||
</.header> | ||
<.simple_form for={@form} id="search-new-form" phx-submit="search"> | ||
<.input field={@form[:search]} type="text" label="Search" /> | ||
<:actions> | ||
<.button phx-disable-with="Searching...">Search</.button> | ||
</:actions> | ||
</.simple_form> | ||
<ul :if={@results} class="mt-4 divide-y divide-zinc-300"> | ||
<li :for={{place_id, result} <- @results}> | ||
<button | ||
phx-click={JS.push("import", value: %{place_id: place_id})} | ||
phx-disable-with="Importing..." | ||
> | ||
<%= result.display_name %> | ||
</button> | ||
</li> | ||
<li :if={@results == []}> | ||
<a href={~p"/restaurants/new-by-id"} target="_blank"> | ||
Add by osm_type / osm_id | ||
</a> | ||
</li> | ||
</ul> | ||
""" | ||
end | ||
|
||
@impl true | ||
def mount(_params, _session, socket) do | ||
{:ok, socket |> assign(form: to_form(%{})) |> assign(results: %{})} | ||
end | ||
|
||
@impl true | ||
def handle_event("search", %{"search" => search}, socket) do | ||
{:noreply, socket |> assign(results: Osm.search_restaurants(search))} | ||
end | ||
|
||
def handle_event("import", %{"place_id" => place_id}, socket) do | ||
place = socket.assigns.results[place_id] | ||
{:ok, restaurant} = Osm.nominatim_get_details(place.osm_type, place.osm_id) | ||
Restaurants.create_restaurant(restaurant) | ||
{:noreply, socket} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.