From 0ab2e5ba2b0631b28b5b1405559237b3913c878f Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Sun, 23 Mar 2025 17:11:39 +0100 Subject: 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 --- lib/mix/tasks/silmataivas.user.new.ex | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/mix/tasks/silmataivas.user.new.ex (limited to 'lib/mix') diff --git a/lib/mix/tasks/silmataivas.user.new.ex b/lib/mix/tasks/silmataivas.user.new.ex new file mode 100644 index 0000000..fe10c7f --- /dev/null +++ b/lib/mix/tasks/silmataivas.user.new.ex @@ -0,0 +1,48 @@ +defmodule Mix.Tasks.Silmataivas.User.New do + use Mix.Task + + @shortdoc "Creates a new user and prints its API token." + + @moduledoc """ + Creates a new user. + + mix silmataivas.user.new + mix silmataivas.user.new + mix silmataivas.user.new + + This task starts the application and creates a user using the Silmataivas.Users context. + + ## Options + * `` - An optional user ID to use. If not provided, a UUID will be generated. + * `` - An optional role, must be either "user" or "admin". Defaults to "user". + """ + + def run(args) do + Mix.Task.run("app.start", []) + + {user_id, role} = + case args do + [provided_id, provided_role | _] -> {provided_id, provided_role} + [provided_id | _] -> {provided_id, "user"} + [] -> {Ecto.UUID.generate(), "user"} + end + + # Validate role + unless role in ["user", "admin"] do + Mix.raise("Invalid role: #{role}. Role must be either \"user\" or \"admin\".") + end + + user_params = %{user_id: user_id, role: role} + + case Silmataivas.Users.create_user(user_params) do + {:ok, user} -> + IO.puts("\n✅ User created successfully!") + IO.puts(" User ID (API token): #{user.user_id}") + IO.puts(" Role: #{user.role}") + + {:error, changeset} -> + IO.puts("\n❌ Failed to create user:") + IO.inspect(changeset.errors) + end + end +end -- cgit v1.2.3