2019-12-05 05:12:49 +01:00
|
|
|
defmodule PhilomenaWeb.Gallery.ImageController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Galleries.Gallery
|
|
|
|
alias Philomena.Galleries
|
2020-09-08 05:47:19 +02:00
|
|
|
alias Philomena.Images.Image
|
2019-12-05 05:12:49 +01:00
|
|
|
|
2020-01-23 18:32:26 +01:00
|
|
|
plug PhilomenaWeb.FilterBannedUsersPlug
|
|
|
|
|
2019-12-05 05:12:49 +01:00
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :edit, delete: :edit
|
|
|
|
plug :load_and_authorize_resource, model: Gallery, id_name: "gallery_id", persisted: true
|
|
|
|
|
|
|
|
plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
|
|
|
|
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
|
|
|
|
|
|
|
|
def create(conn, _params) do
|
2020-09-08 05:47:19 +02:00
|
|
|
case Galleries.add_image_to_gallery(conn.assigns.gallery, conn.assigns.image) do
|
|
|
|
{:ok, _gallery} ->
|
|
|
|
json(conn, %{})
|
|
|
|
|
|
|
|
_error ->
|
|
|
|
conn
|
|
|
|
|> put_status(:bad_request)
|
|
|
|
|> json(%{})
|
|
|
|
end
|
2019-12-05 05:12:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, _params) do
|
2020-09-08 05:47:19 +02:00
|
|
|
case Galleries.remove_image_from_gallery(conn.assigns.gallery, conn.assigns.image) do
|
|
|
|
{:ok, _gallery} ->
|
|
|
|
json(conn, %{})
|
|
|
|
|
|
|
|
_error ->
|
|
|
|
conn
|
|
|
|
|> put_status(:bad_request)
|
|
|
|
|> json(%{})
|
|
|
|
end
|
2019-12-05 05:12:49 +01:00
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
end
|