2020-03-03 12:23:53 +01:00
|
|
|
defmodule PhilomenaWeb.Api.Json.ProfileController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users.User
|
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
2020-03-30 03:11:38 +02:00
|
|
|
user =
|
2020-03-03 12:23:53 +01:00
|
|
|
User
|
|
|
|
|> where(id: ^id)
|
|
|
|
|> preload(public_links: :tag, awards: :badge)
|
|
|
|
|> Repo.one()
|
|
|
|
|
|
|
|
cond do
|
2020-03-30 03:11:38 +02:00
|
|
|
is_nil(user) or user.deleted_at ->
|
2020-03-03 12:23:53 +01:00
|
|
|
conn
|
|
|
|
|> put_status(:not_found)
|
|
|
|
|> text("")
|
|
|
|
|
|
|
|
true ->
|
2020-03-30 03:11:38 +02:00
|
|
|
render(conn, "show.json", user: user)
|
2020-03-03 12:23:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|