|
@@ -83,7 +83,6 @@ defmodule Vaccins.LocationStore do
|
|
|
import Ecto.Changeset
|
|
import Ecto.Changeset
|
|
|
alias Vaccins.Queries.Doctolib
|
|
alias Vaccins.Queries.Doctolib
|
|
|
@name Vaccins.LocationStore
|
|
@name Vaccins.LocationStore
|
|
|
- @file_path "./location_store.json"
|
|
|
|
|
|
|
|
|
|
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: @name)
|
|
def start_link(opts), do: GenServer.start_link(__MODULE__, opts, name: @name)
|
|
|
|
|
|
|
@@ -154,7 +153,7 @@ defmodule Vaccins.LocationStore do
|
|
|
%{locations: locations |> Map.new(&{&1.id, &1})}
|
|
%{locations: locations |> Map.new(&{&1.id, &1})}
|
|
|
else
|
|
else
|
|
|
{:error, reason} ->
|
|
{:error, reason} ->
|
|
|
- Logger.error("Could not read file #{@file_path} : #{reason}")
|
|
|
|
|
|
|
+ Logger.error("Could not read file #{file_path()} : #{reason}")
|
|
|
%{locations: %{}}
|
|
%{locations: %{}}
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
@@ -162,7 +161,7 @@ defmodule Vaccins.LocationStore do
|
|
|
defp read_file(),
|
|
defp read_file(),
|
|
|
do:
|
|
do:
|
|
|
with(
|
|
with(
|
|
|
- {:ok, content} <- File.read(@file_path),
|
|
|
|
|
|
|
+ {:ok, content} <- file_path() |> File.read(),
|
|
|
{:ok, decoded} <- Jason.decode(content, keys: :atoms),
|
|
{:ok, decoded} <- Jason.decode(content, keys: :atoms),
|
|
|
do: {:ok, decoded |> Enum.map(&Location.from_json/1)}
|
|
do: {:ok, decoded |> Enum.map(&Location.from_json/1)}
|
|
|
)
|
|
)
|
|
@@ -174,6 +173,8 @@ defmodule Vaccins.LocationStore do
|
|
|
with(
|
|
with(
|
|
|
{:ok, encoded} <-
|
|
{:ok, encoded} <-
|
|
|
Jason.encode(locations |> Enum.map(&(&1 |> Map.from_struct())), pretty: true),
|
|
Jason.encode(locations |> Enum.map(&(&1 |> Map.from_struct())), pretty: true),
|
|
|
- do: File.write(@file_path, encoded)
|
|
|
|
|
|
|
+ do: file_path() |> File.write(encoded)
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ defp file_path(), do: Application.app_dir(:vaccins, ["priv", "data", "location_store.json"])
|
|
|
end
|
|
end
|