philomena/lib/philomena_web/controllers/api/json/profile_controller.ex
liamwhite 723bfa213f
Use JSON views for API (#64)
* AwardJson, LinkJson, UserJson to views

* FilterJson -> view

* ForumJson -> view

* TopicJson -> view

* PostJson -> view

* TagJson -> view

* CommentJson -> view

* GalleryJson -> view
2020-03-29 21:11:38 -04:00

25 lines
513 B
Elixir
Executable file

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
user =
User
|> where(id: ^id)
|> preload(public_links: :tag, awards: :badge)
|> Repo.one()
cond do
is_nil(user) or user.deleted_at ->
conn
|> put_status(:not_found)
|> text("")
true ->
render(conn, "show.json", user: user)
end
end
end