docbrown/app/controllers/push_notification_subscriptions_controller.rb
Mac Siri 2e647cedb4 Add more test coverage (#1829)
* Create github repos request spec

* Create article_mutes_spec.rb

* Create moderation_service_spec.rb

* Create push notification subscriptions spec

* Add PodcastEpisodeDecorator specs

* Remove randomness in test

* Create specs for ArticleWithVideoCreationService

* Update spec/decorators/podcast_episode_decorator_spec.rb

Co-Authored-By: maestromac <krairit.siri@gmail.com>
2019-02-22 09:16:57 -08:00

19 lines
618 B
Ruby

class PushNotificationSubscriptionsController < ApplicationController
def create
@subscription = PushNotificationSubscription.where(endpoint: pns_params[:endpoint]).
first_or_create(
auth_key: pns_params[:keys][:auth],
p256dh_key: pns_params[:keys][:p256dh],
endpoint: pns_params[:endpoint],
user_id: current_user.id,
notification_type: "browser",
)
render json: { status: "success", endpoint: @subscription.endpoint }, status: 201
end
private
def pns_params
params.require(:subscription).permit({ keys: %i[auth p256dh] }, :endpoint)
end
end