Packages
servicex_matching
0.0.1
This library is a summary of the functions that are generally required for Matching Web service development.
Current section
Files
Jump to
Current section
Files
lib/servicex_matching_web/views/user_profile_view.ex
defmodule ServicexMatchingWeb.UserProfileView do
use ServicexMatchingWeb, :view
alias ServicexMatchingWeb.UserProfileView
alias ServicexWeb.UserView
alias ServicexMatchingWeb.RecordView
alias ServicexMatchingWeb.TagView
def render("index.json", %{user_profiles: user_profiles}) do
render_many(user_profiles, UserProfileView, "user_profile.json")
end
def render("show.json", %{user_profile: user_profile}) do
render_one(user_profile, UserProfileView, "user_profile.json")
end
def render("user_profile.json", %{user_profile: user_profile}) do
result_map = %{id: user_profile.id,
user_type: user_profile.user_type,
organization_id: user_profile.organization_id,
icon_img_url: user_profile.icon_img_url,
back_ground_img_url: user_profile.back_ground_img_url,
birthday: user_profile.birthday,
location: user_profile.location,
zip_code: user_profile.zip_code,
address1: user_profile.address1,
address2: user_profile.address2,
lock_version: user_profile.lock_version,
}
result_map =
if Ecto.assoc_loaded?(user_profile.user) do
Map.put(result_map, :user, UserView.render("user.json", %{user: user_profile.user}))
else
Map.put(result_map, :user, nil)
end
result_map =
if Ecto.assoc_loaded?(user_profile.records) do
Map.put(result_map, :records, RecordView.render("index.json", %{records: user_profile.records}))
else
Map.put(result_map, :records, [])
end
result_map =
if Ecto.assoc_loaded?(user_profile.user_profile_tags) do
Map.put(result_map, :user_profile_tags, TagView.render("index.json", %{tags: user_profile.user_profile_tags}))
else
Map.put(result_map, :user_profile_tags, [])
end
end
end