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
|
|
|
|
alias EventosWeb.AccountView
|
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
|
|
|
|
%{id: user.id,
|
|
|
|
role: user.role,
|
2018-01-16 19:45:09 +01:00
|
|
|
account: render_one(user.account, AccountView, "acccount_basic.json")
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("user.json", %{user: user}) do
|
|
|
|
%{id: user.id,
|
|
|
|
role: user.role,
|
|
|
|
account: render_one(user.account, AccountView, "account.json")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("user_private.json", %{user: user}) do
|
|
|
|
%{id: user.id,
|
2018-01-09 17:52:26 +01:00
|
|
|
email: user.email,
|
2018-01-13 23:33:03 +01:00
|
|
|
role: user.role,
|
2018-01-09 17:52:26 +01:00
|
|
|
}
|
|
|
|
end
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|