mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
32 lines
789 B
Elixir
32 lines
789 B
Elixir
|
defmodule PhilomenaWeb.UserJson do
|
||
|
|
||
|
alias PhilomenaWeb.LinksJson
|
||
|
alias PhilomenaWeb.AwardsJson
|
||
|
|
||
|
def as_json(conn, user) do
|
||
|
%{
|
||
|
id: user.id,
|
||
|
name: user.name,
|
||
|
slug: user.slug,
|
||
|
role: role(user),
|
||
|
description: user.description,
|
||
|
avatar_url: user.avatar,
|
||
|
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,
|
||
|
links: Enum.map(user.public_links, &LinksJson.as_json(conn, &1)),
|
||
|
awards: Enum.map(user.awards, &AwardsJson.as_json(conn, &1))
|
||
|
}
|
||
|
end
|
||
|
|
||
|
defp role(%{hide_default_role: true}) do
|
||
|
"user"
|
||
|
end
|
||
|
|
||
|
defp role(user) do
|
||
|
user.role
|
||
|
end
|
||
|
end
|