-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dp/upgrade-guardian-controller
- Loading branch information
Showing
14 changed files
with
202 additions
and
71 deletions.
There are no files selected for viewing
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
10 changes: 4 additions & 6 deletions
10
lib/bokken_web/views/admin/ninja_view.ex → ...web/controllers/admin/ninja/ninja_json.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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule BokkenWeb.NinjaJSON do | ||
alias Bokken.Uploaders.Avatar | ||
alias BokkenWeb.SkillJSON | ||
|
||
def index(%{ninjas: ninjas}) do | ||
%{data: for(ninja <- ninjas, do: data(ninja))} | ||
end | ||
|
||
def show(%{ninja: ninja}) do | ||
%{data: data(ninja)} | ||
end | ||
|
||
def ninja(%{ninja: ninja, current_user: current_user}) do | ||
data(ninja) | ||
|> Map.merge(personal(ninja, current_user)) | ||
|> Map.merge(sensitive(ninja, current_user)) | ||
end | ||
|
||
def data(ninja) do | ||
%{ | ||
id: ninja.id, | ||
photo: Avatar.url({ninja.photo, ninja}, :thumb), | ||
first_name: ninja.first_name, | ||
last_name: ninja.last_name, | ||
belt: ninja.belt, | ||
socials: ninja.socials, | ||
since: ninja.inserted_at, | ||
guardian_id: ninja.guardian_id | ||
} | ||
|> Map.merge(skills(ninja)) | ||
end | ||
|
||
defp personal(ninja, current_user) | ||
when current_user.role == :organizer or current_user.id == ninja.id do | ||
%{ | ||
birthday: ninja.birthday | ||
} | ||
end | ||
|
||
defp personal(_ninja, _current_user), do: %{} | ||
|
||
defp sensitive(ninja, current_user) when current_user.role in [:organizer, :mentor] do | ||
%{ | ||
notes: ninja.notes | ||
} | ||
end | ||
|
||
defp sensitive(_ninja, _current_user), do: %{} | ||
|
||
defp skills(ninja) do | ||
if Ecto.assoc_loaded?(ninja.skills) do | ||
%{skills: for(skill <- ninja.skills, do: SkillJSON.data(skill))} | ||
else | ||
%{} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule BokkenWeb.SkillJSON do | ||
def index(%{skills: skills}) do | ||
%{data: for(skill <- skills, do: data(%{skill: skill}))} | ||
end | ||
|
||
def show(%{skill: skill}) do | ||
%{data: data(%{skill: skill})} | ||
end | ||
|
||
def error(%{reason: reason}) do | ||
%{error: reason} | ||
end | ||
|
||
def data(%{skill: skill}) do | ||
%{ | ||
id: skill.id, | ||
name: skill.name, | ||
description: skill.description | ||
} | ||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.