FEATURE: Notification API Endpoints for Admins

* create/update/delete notification api with external url
* remove external url feature
* Fix Travis CI build error (add new line)
* Fix Travis CI build error
This commit is contained in:
Muhlis Cahyono
2018-02-13 13:38:26 +07:00
committed by Sam
parent 14d0450bef
commit cc3cf6588b
3 changed files with 194 additions and 64 deletions

View File

@ -3,6 +3,8 @@ require_dependency 'notification_serializer'
class NotificationsController < ApplicationController
requires_login
before_action :ensure_admin, only: [:create, :update, :destroy] # only admin can create/edit/delete notification
before_action :set_notification, only: [:update, :destroy]
def index
user =
@ -64,4 +66,33 @@ class NotificationsController < ApplicationController
render json: success_json
end
def create
@notification = Notification.create!(notification_params)
render_notification
end
def update
@notification.update!(notification_params)
render_notification
end
def destroy
@notification.destroy!
render json: success_json
end
private
def set_notification
@notification = Notification.find(params[:id])
end
def notification_params
params.permit(:notification_type, :user_id, :data, :read, :topic_id, :post_number, :post_action_id)
end
def render_notification
render_json_dump(NotificationSerializer.new(@notification, scope: guardian, root: false))
end
end