philomena/lib/philomena_web/controllers/api/json/image_controller.ex

27 lines
528 B
Elixir
Raw Normal View History

2019-12-04 01:50:23 +01:00
defmodule PhilomenaWeb.Api.Json.ImageController do
use PhilomenaWeb, :controller
alias PhilomenaWeb.ImageJson
alias Philomena.Images.Image
2019-12-31 06:10:50 +01:00
alias Philomena.Repo
import Ecto.Query
2019-12-04 01:50:23 +01:00
2019-12-31 06:10:50 +01:00
def show(conn, %{"id" => id}) do
image =
Image
|> where(id: ^id)
|> preload([:tags, :user, :intensity])
|> Repo.one()
2019-12-04 01:50:23 +01:00
2019-12-31 06:10:50 +01:00
case image do
nil ->
conn
|> put_status(:not_found)
|> text("")
_ ->
json(conn, %{image: ImageJson.as_json(conn, image)})
end
2019-12-04 01:50:23 +01:00
end
end