2020-01-01 00:25:11 +01:00
|
|
|
defmodule PhilomenaWeb.Api.Json.CommentController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Comments.Comment
|
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
2020-01-11 05:20:19 +01:00
|
|
|
comment =
|
2020-01-01 00:25:11 +01:00
|
|
|
Comment
|
|
|
|
|> where(id: ^id)
|
|
|
|
|> preload([:image, :user])
|
|
|
|
|> Repo.one()
|
|
|
|
|
|
|
|
cond do
|
|
|
|
is_nil(comment) or comment.destroyed_content ->
|
|
|
|
conn
|
|
|
|
|> put_status(:not_found)
|
|
|
|
|> text("")
|
|
|
|
|
|
|
|
comment.image.hidden_from_users ->
|
|
|
|
conn
|
|
|
|
|> put_status(:forbidden)
|
|
|
|
|> text("")
|
|
|
|
|
|
|
|
true ->
|
2020-03-30 03:11:38 +02:00
|
|
|
render(conn, "show.json", comment: comment)
|
2020-01-01 00:25:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|