summaryrefslogtreecommitdiff
path: root/lib/silmataivas_web/controllers
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-07-14 19:34:59 +0300
committerDawid Rycerz <dawid@rycerz.xyz>2025-07-14 19:34:59 +0300
commit50ce8cb96b2b218751c2fc2a6b19372f51846acc (patch)
treee2c634d2ce856062d527667d47815a05a53361c8 /lib/silmataivas_web/controllers
parent0ab2e5ba2b0631b28b5b1405559237b3913c878f (diff)
feat: rewrite in rust
Diffstat (limited to 'lib/silmataivas_web/controllers')
-rw-r--r--lib/silmataivas_web/controllers/changeset_json.ex25
-rw-r--r--lib/silmataivas_web/controllers/error_json.ex21
-rw-r--r--lib/silmataivas_web/controllers/fallback_controller.ex24
-rw-r--r--lib/silmataivas_web/controllers/health_controller.ex9
-rw-r--r--lib/silmataivas_web/controllers/location_controller.ex46
-rw-r--r--lib/silmataivas_web/controllers/location_json.ex25
6 files changed, 0 insertions, 150 deletions
diff --git a/lib/silmataivas_web/controllers/changeset_json.ex b/lib/silmataivas_web/controllers/changeset_json.ex
deleted file mode 100644
index ac0226d..0000000
--- a/lib/silmataivas_web/controllers/changeset_json.ex
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule SilmataivasWeb.ChangesetJSON do
- @doc """
- Renders changeset errors.
- """
- def error(%{changeset: changeset}) do
- # When encoded, the changeset returns its errors
- # as a JSON object. So we just pass it forward.
- %{errors: Ecto.Changeset.traverse_errors(changeset, &translate_error/1)}
- end
-
- defp translate_error({msg, opts}) do
- # You can make use of gettext to translate error messages by
- # uncommenting and adjusting the following code:
-
- # if count = opts[:count] do
- # Gettext.dngettext(SilmataivasWeb.Gettext, "errors", msg, msg, count, opts)
- # else
- # Gettext.dgettext(SilmataivasWeb.Gettext, "errors", msg, opts)
- # end
-
- Enum.reduce(opts, msg, fn {key, value}, acc ->
- String.replace(acc, "%{#{key}}", fn _ -> to_string(value) end)
- end)
- end
-end
diff --git a/lib/silmataivas_web/controllers/error_json.ex b/lib/silmataivas_web/controllers/error_json.ex
deleted file mode 100644
index a2ca902..0000000
--- a/lib/silmataivas_web/controllers/error_json.ex
+++ /dev/null
@@ -1,21 +0,0 @@
-defmodule SilmataivasWeb.ErrorJSON do
- @moduledoc """
- This module is invoked by your endpoint in case of errors on JSON requests.
-
- See config/config.exs.
- """
-
- # If you want to customize a particular status code,
- # you may add your own clauses, such as:
- #
- # def render("500.json", _assigns) do
- # %{errors: %{detail: "Internal Server Error"}}
- # end
-
- # By default, Phoenix returns the status message from
- # the template name. For example, "404.json" becomes
- # "Not Found".
- def render(template, _assigns) do
- %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
- end
-end
diff --git a/lib/silmataivas_web/controllers/fallback_controller.ex b/lib/silmataivas_web/controllers/fallback_controller.ex
deleted file mode 100644
index f315110..0000000
--- a/lib/silmataivas_web/controllers/fallback_controller.ex
+++ /dev/null
@@ -1,24 +0,0 @@
-defmodule SilmataivasWeb.FallbackController do
- @moduledoc """
- Translates controller action results into valid `Plug.Conn` responses.
-
- See `Phoenix.Controller.action_fallback/1` for more details.
- """
- use SilmataivasWeb, :controller
-
- # This clause handles errors returned by Ecto's insert/update/delete.
- def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
- conn
- |> put_status(:unprocessable_entity)
- |> put_view(json: SilmataivasWeb.ChangesetJSON)
- |> render(:error, changeset: changeset)
- end
-
- # This clause is an example of how to handle resources that cannot be found.
- def call(conn, {:error, :not_found}) do
- conn
- |> put_status(:not_found)
- |> put_view(html: SilmataivasWeb.ErrorHTML, json: SilmataivasWeb.ErrorJSON)
- |> render(:"404")
- end
-end
diff --git a/lib/silmataivas_web/controllers/health_controller.ex b/lib/silmataivas_web/controllers/health_controller.ex
deleted file mode 100644
index 959b84b..0000000
--- a/lib/silmataivas_web/controllers/health_controller.ex
+++ /dev/null
@@ -1,9 +0,0 @@
-defmodule SilmataivasWeb.HealthController do
- use SilmataivasWeb, :controller
-
- def index(conn, _params) do
- conn
- |> put_status(:ok)
- |> json(%{status: "ok"})
- end
-end
diff --git a/lib/silmataivas_web/controllers/location_controller.ex b/lib/silmataivas_web/controllers/location_controller.ex
deleted file mode 100644
index d494d59..0000000
--- a/lib/silmataivas_web/controllers/location_controller.ex
+++ /dev/null
@@ -1,46 +0,0 @@
-defmodule SilmataivasWeb.LocationController do
- use SilmataivasWeb, :controller
-
- alias Silmataivas.Locations
- alias Silmataivas.Locations.Location
-
- action_fallback SilmataivasWeb.FallbackController
-
- def index(conn, _params) do
- locations = Locations.list_locations()
- render(conn, :index, locations: locations)
- end
-
- def create(conn, params) do
- user = conn.assigns.current_user
- params = Map.put(params, "user_id", user.id)
-
- with {:ok, %Location{} = location} <- Locations.create_location(params) do
- conn
- |> put_status(:created)
- |> put_resp_header("location", ~p"/api/locations/#{location}")
- |> render(:show, location: location)
- end
- end
-
- def show(conn, %{"id" => id}) do
- location = Locations.get_location!(id)
- render(conn, :show, location: location)
- end
-
- def update(conn, %{"id" => id, "location" => location_params}) do
- location = Locations.get_location!(id)
-
- with {:ok, %Location{} = location} <- Locations.update_location(location, location_params) do
- render(conn, :show, location: location)
- end
- end
-
- def delete(conn, %{"id" => id}) do
- location = Locations.get_location!(id)
-
- with {:ok, %Location{}} <- Locations.delete_location(location) do
- send_resp(conn, :no_content, "")
- end
- end
-end
diff --git a/lib/silmataivas_web/controllers/location_json.ex b/lib/silmataivas_web/controllers/location_json.ex
deleted file mode 100644
index db7e469..0000000
--- a/lib/silmataivas_web/controllers/location_json.ex
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule SilmataivasWeb.LocationJSON do
- alias Silmataivas.Locations.Location
-
- @doc """
- Renders a list of locations.
- """
- def index(%{locations: locations}) do
- %{data: for(location <- locations, do: data(location))}
- end
-
- @doc """
- Renders a single location.
- """
- def show(%{location: location}) do
- %{data: data(location)}
- end
-
- defp data(%Location{} = location) do
- %{
- id: location.id,
- latitude: location.latitude,
- longitude: location.longitude
- }
- end
-end