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

36 lines
1 KiB
Elixir
Raw Normal View History

2019-12-05 05:27:40 +01:00
defmodule PhilomenaWeb.Channel.SubscriptionController do
use PhilomenaWeb, :controller
alias Philomena.Channels.Channel
alias Philomena.Channels
plug PhilomenaWeb.CanaryMapPlug, create: :show, delete: :show
plug :load_and_authorize_resource, model: Channel, id_name: "channel_id", persisted: true
def create(conn, _params) do
channel = conn.assigns.channel
user = conn.assigns.current_user
case Channels.create_subscription(channel, user) do
{:ok, _subscription} ->
render(conn, "_subscription.html", channel: channel, watching: true, layout: false)
{:error, _changeset} ->
render(conn, "_error.html", layout: false)
end
end
def delete(conn, _params) do
channel = conn.assigns.channel
user = conn.assigns.current_user
case Channels.delete_subscription(channel, user) do
{:ok, _subscription} ->
render(conn, "_subscription.html", channel: channel, watching: false, layout: false)
{:error, _changeset} ->
render(conn, "_error.html", layout: false)
end
end
2020-01-11 05:20:19 +01:00
end