philomena/lib/philomena_web/controllers/image/description_controller.ex

30 lines
921 B
Elixir
Raw Normal View History

2019-11-29 06:39:15 +01:00
defmodule PhilomenaWeb.Image.DescriptionController do
use PhilomenaWeb, :controller
alias Philomena.Textile.Renderer
alias Philomena.Images.Image
alias Philomena.Images
plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.CanaryMapPlug, update: :edit_description
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def update(conn, %{"image" => image_params}) do
image = conn.assigns.image
case Images.update_description(image, image_params) do
{:ok, image} ->
Images.reindex_image(image)
2019-12-01 18:11:00 +01:00
body = Renderer.render_one(%{body: image.description}, conn)
2019-11-29 06:39:15 +01:00
conn
|> put_view(PhilomenaWeb.ImageView)
|> render("_description.html", layout: false, image: image, body: body)
{:error, changeset} ->
conn
|> render("_form.html", layout: false, image: image, changeset: changeset)
end
end
end