mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
196c5e14b6
* API additions for user interactions on single images * removed ability to render without supplying interactions
30 lines
651 B
Elixir
30 lines
651 B
Elixir
defmodule PhilomenaWeb.Api.Json.ImageController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.Images.Image
|
|
alias Philomena.Interactions
|
|
alias Philomena.Repo
|
|
import Ecto.Query
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
user = conn.assigns.current_user
|
|
|
|
image =
|
|
Image
|
|
|> where(id: ^id)
|
|
|> preload([:tags, :user, :intensity])
|
|
|> Repo.one()
|
|
|
|
case image do
|
|
nil ->
|
|
conn
|
|
|> put_status(:not_found)
|
|
|> text("")
|
|
|
|
_ ->
|
|
interactions = Interactions.user_interactions([image], user)
|
|
|
|
render(conn, "show.json", image: image, interactions: interactions)
|
|
end
|
|
end
|
|
end
|