neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
once agian
6eef60d · gmorell · 2022-08-05 19:42
Files changed
modified
apps/room_sanctum/lib/room_sanctum/accounts.ex
+110
−0
@@ -350,4 +350,114 @@ defmodule RoomSanctum.Accounts do
| 350 | 350 | {:error, :user, changeset, _} -> {:error, changeset} |
| 351 | 351 | end |
| 352 | 352 | end |
| 353 | + | |
| 354 | + | |
| 355 | + ### Copied from hermes because of fuckery | |
| 356 | + alias RoomHermes.Accounts.RabbitUser | |
| 357 | + | |
| 358 | + @doc """ | |
| 359 | + Returns the list of users_rabbit. | |
| 360 | + | |
| 361 | + ## Examples | |
| 362 | + | |
| 363 | + iex> list_users_rabbit() | |
| 364 | + [%RabbitUser{}, ...] | |
| 365 | + | |
| 366 | + """ | |
| 367 | + def list_users_rabbit do | |
| 368 | + Repo.all(RabbitUser) | |
| 369 | + end | |
| 370 | + | |
| 371 | + def list_users_rabbit({:user, uid}) do | |
| 372 | + Repo.all(from r in RabbitUser, where: r.user_id == ^uid) | |
| 373 | + end | |
| 374 | + | |
| 375 | + @doc """ | |
| 376 | + Gets a single rabbit_user. | |
| 377 | + | |
| 378 | + Raises `Ecto.NoResultsError` if the Rabbit user does not exist. | |
| 379 | + | |
| 380 | + ## Examples | |
| 381 | + | |
| 382 | + iex> get_rabbit_user!(123) | |
| 383 | + %RabbitUser{} | |
| 384 | + | |
| 385 | + iex> get_rabbit_user!(456) | |
| 386 | + ** (Ecto.NoResultsError) | |
| 387 | + | |
| 388 | + """ | |
| 389 | + def get_rabbit_user!(id), do: Repo.get!(RabbitUser, id) | |
| 390 | + | |
| 391 | + @doc """ | |
| 392 | + Creates a rabbit_user. | |
| 393 | + | |
| 394 | + ## Examples | |
| 395 | + | |
| 396 | + iex> create_rabbit_user(%{field: value}) | |
| 397 | + {:ok, %RabbitUser{}} | |
| 398 | + | |
| 399 | + iex> create_rabbit_user(%{field: bad_value}) | |
| 400 | + {:error, %Ecto.Changeset{}} | |
| 401 | + | |
| 402 | + """ | |
| 403 | + def create_rabbit_user(attrs \\ %{}) do | |
| 404 | + %RabbitUser{} | |
| 405 | + |> RabbitUser.changeset(attrs) | |
| 406 | + |> Repo.insert() | |
| 407 | + end | |
| 408 | + | |
| 409 | + @doc """ | |
| 410 | + Updates a rabbit_user. | |
| 411 | + | |
| 412 | + ## Examples | |
| 413 | + | |
| 414 | + iex> update_rabbit_user(rabbit_user, %{field: new_value}) | |
| 415 | + {:ok, %RabbitUser{}} | |
| 416 | + | |
| 417 | + iex> update_rabbit_user(rabbit_user, %{field: bad_value}) | |
| 418 | + {:error, %Ecto.Changeset{}} | |
| 419 | + | |
| 420 | + """ | |
| 421 | + def update_rabbit_user(%RabbitUser{} = rabbit_user, attrs) do | |
| 422 | + rabbit_user | |
| 423 | + |> RabbitUser.changeset(attrs) | |
| 424 | + |> Repo.update() | |
| 425 | + end | |
| 426 | + | |
| 427 | + @doc """ | |
| 428 | + Deletes a rabbit_user. | |
| 429 | + | |
| 430 | + ## Examples | |
| 431 | + | |
| 432 | + iex> delete_rabbit_user(rabbit_user) | |
| 433 | + {:ok, %RabbitUser{}} | |
| 434 | + | |
| 435 | + iex> delete_rabbit_user(rabbit_user) | |
| 436 | + {:error, %Ecto.Changeset{}} | |
| 437 | + | |
| 438 | + """ | |
| 439 | + def delete_rabbit_user(%RabbitUser{} = rabbit_user) do | |
| 440 | + Repo.delete(rabbit_user) | |
| 441 | + end | |
| 442 | + | |
| 443 | + @doc """ | |
| 444 | + Returns an `%Ecto.Changeset{}` for tracking rabbit_user changes. | |
| 445 | + | |
| 446 | + ## Examples | |
| 447 | + | |
| 448 | + iex> change_rabbit_user(rabbit_user) | |
| 449 | + %Ecto.Changeset{data: %RabbitUser{}} | |
| 450 | + | |
| 451 | + """ | |
| 452 | + def change_rabbit_user(%RabbitUser{} = rabbit_user, attrs \\ %{}) do | |
| 453 | + RabbitUser.changeset(rabbit_user, attrs) | |
| 454 | + end | |
| 455 | + | |
| 456 | + def find_rabbit_user(username) do | |
| 457 | + from(r in RabbitUser, where: r.username == ^username) |> Repo.one | |
| 458 | + end | |
| 459 | + | |
| 460 | + def find_rabbit_user(username, password) do | |
| 461 | + from(r in RabbitUser, where: r.username == ^username and r.password == ^password) |> Repo.one | |
| 462 | + end | |
| 353 | 463 | end |
added
apps/room_sanctum/lib/room_sanctum/accounts/rabbit_user.ex
+20
−0
@@ -0,0 +1,20 @@
| 1 | +defmodule RoomHermes.Accounts.RabbitUser do | |
| 2 | + use Ecto.Schema | |
| 3 | + import Ecto.Changeset | |
| 4 | + | |
| 5 | + schema "users_rabbit" do | |
| 6 | + field :password, :string | |
| 7 | + field :username, :binary_id | |
| 8 | + field :topic, :string | |
| 9 | + belongs_to :user, RoomSanctum.Accounts.User | |
| 10 | + | |
| 11 | + timestamps() | |
| 12 | + end | |
| 13 | + | |
| 14 | + @doc false | |
| 15 | + def changeset(rabbit_user, attrs) do | |
| 16 | + rabbit_user | |
| 17 | + |> cast(attrs, [:username, :password, :topic, :user_id]) | |
| 18 | + |> validate_required([:username, :password, :topic]) | |
| 19 | + end | |
| 20 | +end |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_ankyra/index.ex
+2
−2
@@ -1,8 +1,8 @@
| 1 | 1 | defmodule RoomSanctumWeb.AnkyraLive.Index do |
| 2 | 2 | use RoomSanctumWeb, :live_view_a |
| 3 | 3 | |
| 4 | − alias RoomHermes.Accounts | |
| 5 | − alias RoomHermes.Accounts.RabbitUser | |
| 4 | + alias RoomSanctum.Accounts | |
| 5 | + alias RoomSanctum.Accounts.RabbitUser | |
| 6 | 6 | |
| 7 | 7 | @impl true |
| 8 | 8 | def mount(_params, _session, socket) do |
modified
apps/room_sanctum/room_sanctum.iml
+2
−0
@@ -120,5 +120,7 @@
| 120 | 120 | <orderEntry type="library" name="tailwind" level="project" /> |
| 121 | 121 | <orderEntry type="library" name="healthchex" level="project" /> |
| 122 | 122 | <orderEntry type="library" name="friendlyid" level="project" /> |
| 123 | + <orderEntry type="module" module-name="room_hermes" /> | |
| 124 | + <orderEntry type="module" module-name="room_hermes" /> | |
| 123 | 125 | </component> |
| 124 | 126 | </module> |
Parents: e1fe7a8