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

31 lines
651 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
alias Philomena.Interactions
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
user = conn.assigns.current_user
2019-12-31 06:10:50 +01:00
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("")
_ ->
interactions = Interactions.user_interactions([image], user)
render(conn, "show.json", image: image, interactions: interactions)
2019-12-31 06:10:50 +01:00
end
2019-12-04 01:50:23 +01:00
end
end