Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ninja controller and view #203

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/bokken_web/controllers/admin/ninja/ninja_json.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
defmodule BokkenWeb.Admin.NinjaJSON do
alias Bokken.Accounts.Ninja
alias Bokken.Uploaders.Avatar

def index(%{ninjas: ninjas}) do
%{data: for(ninja <- ninjas, do: data(ninja))}
end

def data(%{ninja: ninja}) do
def data(%Ninja{} = ninja) do
%{
id: ninja.id,
photo: Avatar.url({ninja.photo, ninja}, :thumb),
Expand All @@ -16,10 +17,10 @@ defmodule BokkenWeb.Admin.NinjaJSON do
socials: ninja.socials,
since: ninja.inserted_at
}
|> Map.put(:guardian, guardian_attrs(ninja))
|> Map.put(:guardian, guardian(ninja))
end

defp guardian_attrs(ninja) do
defp guardian(ninja) do
if Ecto.assoc_loaded?(ninja.guardian) do
%{
id: ninja.guardian.id,
Expand Down
4 changes: 2 additions & 2 deletions lib/bokken_web/views/auth_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule BokkenWeb.AuthView do
alias BokkenWeb.AuthView
alias BokkenWeb.GuardianView
alias BokkenWeb.MentorView
alias BokkenWeb.NinjaView
alias BokkenWeb.NinjaJSON
alias BokkenWeb.OrganizerView

def render("me.json", %{user: %{registered: false} = user}) do
Expand All @@ -24,7 +24,7 @@ defmodule BokkenWeb.AuthView do
end

def render("me.json", %{user: %{role: :ninja, ninja: ninja} = user}) do
render_one(ninja, NinjaView, "ninja.json", current_user: user)
NinjaJSON.ninja(%{ninja: ninja, current_user: user})
|> Map.merge(render_one(user, AuthView, "user.json"))
|> Map.put(:ninja_id, ninja.id)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bokken_web/views/enrollment_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule BokkenWeb.EnrollmentView do

alias BokkenWeb.EnrollmentView
alias BokkenWeb.EventView
alias BokkenWeb.NinjaView
alias BokkenWeb.NinjaJSON

def render("index.json", %{enrollments: enrollments, current_user: current_user}) do
%{
Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule BokkenWeb.EnrollmentView do

defp ninja(enrollment, current_user) do
if Ecto.assoc_loaded?(enrollment.ninja) do
%{ninja: render_one(enrollment.ninja, NinjaView, "ninja.json", current_user: current_user)}
%{ninja: NinjaJSON.ninja(%{ninja: enrollment.ninja, current_user: current_user})}
else
%{ninja_id: enrollment.ninja_id}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bokken_web/views/lecture_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule BokkenWeb.LectureView do
alias BokkenWeb.FileJSON
alias BokkenWeb.LectureView
alias BokkenWeb.MentorView
alias BokkenWeb.NinjaView
alias BokkenWeb.NinjaJSON

def render("index.json", %{lectures: lectures, current_user: current_user}) do
%{data: render_many(lectures, LectureView, "lecture.json", current_user: current_user)}
Expand Down Expand Up @@ -35,7 +35,7 @@ defmodule BokkenWeb.LectureView do

defp ninja(lecture, current_user) do
if Ecto.assoc_loaded?(lecture.ninja) do
%{ninja: render_one(lecture.ninja, NinjaView, "ninja.json", current_user: current_user)}
%{ninja: NinjaJSON.ninja(%{ninja: lecture.ninja, current_user: current_user})}
else
%{ninja_id: lecture.ninja_id}
end
Expand Down
59 changes: 0 additions & 59 deletions lib/bokken_web/views/ninja_view.ex

This file was deleted.

Loading