philomena/lib/philomena_web/controllers/gallery/image_controller.ex

40 lines
1 KiB
Elixir
Raw Permalink Normal View History

2019-12-05 05:12:49 +01:00
defmodule PhilomenaWeb.Gallery.ImageController do
use PhilomenaWeb, :controller
alias Philomena.Galleries.Gallery
alias Philomena.Galleries
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
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
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