2017-12-08 09:58:14 +01:00
|
|
|
defmodule EventosWeb.UserView do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
View for Users
|
|
|
|
"""
|
2017-12-08 09:58:14 +01:00
|
|
|
use EventosWeb, :view
|
2018-01-13 23:33:03 +01:00
|
|
|
alias EventosWeb.UserView
|
2018-05-18 09:56:21 +02:00
|
|
|
alias EventosWeb.ActorView
|
2018-01-09 17:52:26 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def render("index.json", %{users: users}) do
|
|
|
|
%{data: render_many(users, UserView, "user_simple.json")}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show.json", %{user: user}) do
|
|
|
|
%{data: render_one(user, UserView, "user.json")}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show_simple.json", %{user: user}) do
|
|
|
|
%{data: render_one(user, UserView, "user_simple.json")}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("show_with_token.json", %{user: user, token: token}) do
|
2018-01-09 17:52:26 +01:00
|
|
|
%{
|
2018-01-13 23:33:03 +01:00
|
|
|
user: render_one(user, UserView, "user_simple.json"),
|
|
|
|
token: token
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("user_simple.json", %{user: user}) do
|
2018-07-27 10:45:35 +02:00
|
|
|
%{
|
|
|
|
id: user.id,
|
2018-01-13 23:33:03 +01:00
|
|
|
role: user.role,
|
2018-07-10 10:00:07 +02:00
|
|
|
actors: render_many(user.actors, ActorView, "actor_basic.json")
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("user.json", %{user: user}) do
|
2018-07-27 10:45:35 +02:00
|
|
|
%{id: user.id, role: user.role, actors: render_many(user.actors, ActorView, "actor.json")}
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def render("user_private.json", %{user: user}) do
|
2018-07-27 10:45:35 +02:00
|
|
|
%{id: user.id, email: user.email, role: user.role}
|
2018-01-09 17:52:26 +01:00
|
|
|
end
|
2018-07-04 14:29:17 +02:00
|
|
|
|
|
|
|
def render("confirmation.json", %{user: user}) do
|
|
|
|
%{
|
2018-07-27 10:45:35 +02:00
|
|
|
email: user.email
|
2018-07-04 14:29:17 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("password_reset.json", %{user: user}) do
|
|
|
|
%{
|
2018-07-27 10:45:35 +02:00
|
|
|
email: user.email
|
2018-07-04 14:29:17 +02:00
|
|
|
}
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|