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

26 lines
484 B
Elixir
Raw Normal View History

2019-12-04 01:50:23 +01:00
defmodule PhilomenaWeb.Api.Json.ImageController do
use PhilomenaWeb, :controller
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("")
_ ->
2020-03-30 01:39:36 +02:00
render(conn, "show.json", image: image)
2019-12-31 06:10:50 +01:00
end
2019-12-04 01:50:23 +01:00
end
end