Feature: User Notification Objects (#752)

Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-05-01 14:53:43 +05:30
committed by GitHub
parent 66aace7c13
commit 96da27f1f6
35 changed files with 461 additions and 110 deletions

View File

@@ -4,11 +4,6 @@ class Api::V1::Accounts::ContactsController < Api::BaseController
before_action :check_authorization
before_action :fetch_contact, only: [:show, :update]
skip_before_action :authenticate_user!, only: [:create]
skip_before_action :set_current_user, only: [:create]
skip_before_action :check_subscription, only: [:create]
skip_around_action :handle_with_exception, only: [:create]
def index
@contacts = current_account.contacts
end

View File

@@ -0,0 +1,21 @@
class Api::V1::Accounts::NotificationsController < Api::BaseController
protect_from_forgery with: :null_session
before_action :fetch_notification, only: [:update]
def index
@notifications = current_user.notifications.where(account_id: current_account.id)
render json: @notifications
end
def update
@notification.update(read_at: DateTime.now.utc)
render json: @notification
end
private
def fetch_notification
@notification = current_user.notifications.find(params[:id])
end
end

View File

@@ -0,0 +1,18 @@
class Api::V1::NotificationSubscriptionsController < Api::BaseController
before_action :set_user
def create
notification_subscription = @user.notification_subscriptions.create(notification_subscription_params)
render json: notification_subscription
end
private
def set_user
@user = current_user
end
def notification_subscription_params
params.require(:notification_subscription).permit(:subscription_type, subscription_attributes: {})
end
end