2020-01-07 16:35:24 +01:00
|
|
|
defmodule PhilomenaWeb.Api.Json.PostController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Posts.Post
|
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
def show(conn, %{"id" => post_id}) do
|
2020-01-11 05:20:19 +01:00
|
|
|
post =
|
2020-01-07 16:35:24 +01:00
|
|
|
Post
|
|
|
|
|> join(:inner, [p], _ in assoc(p, :topic))
|
|
|
|
|> join(:inner, [_p, t], _ in assoc(t, :forum))
|
|
|
|
|> where(id: ^post_id)
|
|
|
|
|> where(destroyed_content: false)
|
|
|
|
|> where([_p, t], t.hidden_from_users == false)
|
2020-01-11 05:20:19 +01:00
|
|
|
|> where([_p, _t, f], f.access_level == "normal")
|
2020-01-07 16:35:24 +01:00
|
|
|
|> preload([:user, :topic])
|
|
|
|
|> Repo.one()
|
|
|
|
|
|
|
|
cond do
|
|
|
|
is_nil(post) ->
|
|
|
|
conn
|
|
|
|
|> put_status(:not_found)
|
|
|
|
|> text("")
|
|
|
|
|
|
|
|
true ->
|
2020-03-30 03:11:38 +02:00
|
|
|
conn
|
|
|
|
|> put_view(PhilomenaWeb.Api.Json.Forum.Topic.PostView)
|
|
|
|
|> render("show.json", post: post)
|
2020-01-07 16:35:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|