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

36 lines
1 KiB
Elixir
Raw Permalink Normal View History

2019-11-17 18:50:42 +01:00
defmodule PhilomenaWeb.Image.SubscriptionController do
use PhilomenaWeb, :controller
alias Philomena.Images.Image
alias Philomena.Images
2019-11-17 19:18:21 +01:00
plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
2019-11-17 18:50:42 +01:00
plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true
def create(conn, _params) do
image = conn.assigns.image
user = conn.assigns.current_user
case Images.create_subscription(image, user) do
{:ok, _subscription} ->
render(conn, "_subscription.html", image: image, watching: true, layout: false)
{:error, _changeset} ->
render(conn, "_error.html", layout: false)
end
end
def delete(conn, _params) do
image = conn.assigns.image
user = conn.assigns.current_user
case Images.delete_subscription(image, user) do
{:ok, _subscription} ->
render(conn, "_subscription.html", image: image, watching: false, layout: false)
{:error, _changeset} ->
render(conn, "_error.html", layout: false)
end
end
2020-01-11 05:20:19 +01:00
end