-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
219 deletions.
There are no files selected for viewing
27 changes: 21 additions & 6 deletions
27
examples/user_managment/phoenix_live_view_user_management/lib/arcane/profiles.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
defmodule Arcane.Profiles do | ||
import Ecto.Query | ||
|
||
alias Arcane.Profiles.Profile | ||
alias Arcane.Repo | ||
|
||
def get_profile(id: id) do | ||
Repo.get(Profile, id) | ||
end | ||
|
||
def upsert_profile(attrs) do | ||
changeset = Profile.changeset(%Profile{}, attrs) | ||
def create_profile(user_id: user_id) do | ||
changeset = Profile.changeset(%Profile{}, %{id: user_id}) | ||
Repo.insert(changeset, on_conflict: :nothing, conflict_target: [:id]) | ||
end | ||
|
||
def update_profile(%{"id" => profile_id} = attrs) do | ||
changeset = Profile.update_changeset(attrs) | ||
|
||
if changeset.valid? do | ||
updated_at = NaiveDateTime.utc_now() | ||
changes = [{:updated_at, updated_at} | Map.to_list(changeset.changes)] | ||
q = from p in Profile, where: p.id == ^profile_id, select: p | ||
|
||
Repo.insert(changeset, | ||
on_conflict: {:replace_all_except, [:id]}, | ||
conflict_target: :id | ||
) | ||
case Repo.update_all(q, set: changes) do | ||
{1, [profile]} -> {:ok, profile} | ||
_ -> {:error, :failed_to_update_profile} | ||
end | ||
else | ||
{:error, changeset} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...nagment/phoenix_live_view_user_management/lib/arcane_web/components/layouts/app.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<!-- This is the template that all live views will use --> | ||
<main> | ||
<.flash_group flash={@flash} /> | ||
<%= @inner_content %> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.