2020-03-30 03:11:38 +02:00
|
|
|
defmodule PhilomenaWeb.Api.Json.ProfileView do
|
|
|
|
use PhilomenaWeb, :view
|
2020-03-03 12:23:53 +01:00
|
|
|
|
2020-03-30 03:11:38 +02:00
|
|
|
def render("show.json", %{user: user} = assigns) do
|
|
|
|
%{user: render_one(user, PhilomenaWeb.Api.Json.ProfileView, "profile.json", assigns)}
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("profile.json", %{user: user} = assigns) do
|
2020-03-03 12:23:53 +01:00
|
|
|
%{
|
|
|
|
id: user.id,
|
|
|
|
name: user.name,
|
|
|
|
slug: user.slug,
|
|
|
|
role: role(user),
|
|
|
|
description: user.description,
|
|
|
|
avatar_url: avatar_url(user),
|
|
|
|
created_at: user.created_at,
|
|
|
|
comments_count: user.comments_posted_count,
|
|
|
|
uploads_count: user.uploads_count,
|
|
|
|
posts_count: user.forum_posts_count,
|
|
|
|
topics_count: user.topic_count,
|
2020-03-31 17:39:11 +02:00
|
|
|
links:
|
|
|
|
render_many(
|
|
|
|
user.public_links,
|
|
|
|
PhilomenaWeb.Api.Json.UserLinkView,
|
|
|
|
"user_link.json",
|
|
|
|
assigns
|
|
|
|
),
|
2020-03-30 03:11:38 +02:00
|
|
|
awards: render_many(user.awards, PhilomenaWeb.Api.Json.AwardView, "award.json", assigns)
|
2020-03-03 12:23:53 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp role(%{hide_default_role: true}) do
|
|
|
|
"user"
|
|
|
|
end
|
|
|
|
|
|
|
|
defp role(user) do
|
|
|
|
user.role
|
|
|
|
end
|
|
|
|
|
|
|
|
defp avatar_url(%{avatar: nil}) do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
defp avatar_url(user) do
|
|
|
|
Application.get_env(:philomena, :avatar_url_root) <> "/" <> user.avatar
|
|
|
|
end
|
|
|
|
end
|