mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
33 lines
678 B
Elixir
33 lines
678 B
Elixir
|
defmodule PhilomenaWeb.Api.Json.CommentController do
|
||
|
use PhilomenaWeb, :controller
|
||
|
|
||
|
alias PhilomenaWeb.CommentJson
|
||
|
alias Philomena.Comments.Comment
|
||
|
alias Philomena.Repo
|
||
|
import Ecto.Query
|
||
|
|
||
|
def show(conn, %{"id" => id}) do
|
||
|
comment =
|
||
|
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 ->
|
||
|
json(conn, %{comment: CommentJson.as_json(comment)})
|
||
|
|
||
|
end
|
||
|
end
|
||
|
end
|