summaryrefslogtreecommitdiff
path: root/lib/silmataivas_web/controllers/location_controller.ex
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-03-23 17:11:39 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2025-04-05 21:16:51 +0200
commit0ab2e5ba2b0631b28b5b1405559237b3913c878f (patch)
tree791cea788b0a62bc483d0041fbd0c655d2ad49e8 /lib/silmataivas_web/controllers/location_controller.ex
feat: initialize Phoenix application for weather alerts
This commit sets up the initial Silmataivas project structure, including: Phoenix web framework configuration, database models for users and locations, weather polling service, notification system, Docker and deployment configurations, CI/CD pipeline setup
Diffstat (limited to 'lib/silmataivas_web/controllers/location_controller.ex')
-rw-r--r--lib/silmataivas_web/controllers/location_controller.ex46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/silmataivas_web/controllers/location_controller.ex b/lib/silmataivas_web/controllers/location_controller.ex
new file mode 100644
index 0000000..d494d59
--- /dev/null
+++ b/lib/silmataivas_web/controllers/location_controller.ex
@@ -0,0 +1,46 @@
+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