Class: ActivityNotification::NotificationsApiController

Inherits:
NotificationsController show all
Includes:
CommonApiController, Swagger::NotificationsApi
Defined in:
app/controllers/activity_notification/notifications_api_controller.rb

Overview

Controller to manage notifications API.

Direct Known Subclasses

NotificationsApiWithDeviseController

Constant Summary

Constants included from CommonController

CommonController::DEFAULT_VIEW_DIRECTORY

Instance Method Summary collapse

Methods inherited from NotificationsController

#target_view_path

Methods included from StoreController

#store_controller_for_activity_notification

Instance Method Details

#destroy(params) ⇒ JSON

Deletes a notification.

DELETE /:target_type/:target_id/notifications/:id

Returns 204 No Content.

Parameters:

  • params (Hash)

    Request parameters

Returns:

  • (JSON)

    204 No Content



95
96
97
98
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 95

def destroy
  super
  head 204
end

#destroy_all(params) ⇒ JSON

Destroys all notifications of the target matching filter criteria.

POST /:target_type/:target_id/notifications/destroy_all

Returns count: number of destroyed notification records, notifications: destroyed notifications.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filtered_by_type (String) — default: nil

    Notifiable type to filter notifications

  • :filtered_by_group_type (String) — default: nil

    Group type to filter notifications, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance ID to filter notifications, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of notifications to filter

  • :later_than (String) — default: nil

    ISO 8601 format time to filter notifications later than specified time

  • :earlier_than (String) — default: nil

    ISO 8601 format time to filter notifications earlier than specified time

  • :ids (Array) — default: nil

    Array of specific notification IDs to destroy

Returns:

  • (JSON)

    count: number of destroyed notification records, notifications: destroyed notifications



70
71
72
73
74
75
76
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 70

def destroy_all
  super
  render json: {
    count: @destroyed_notifications.size,
    notifications: @destroyed_notifications.as_json(notification_json_options)
  }
end

#index(params) ⇒ JSON

Returns notification index of the target.

GET /:target_type/:target_id/notifications

Returns count: number of notification index records, notifications: notification index.

Parameters:

  • params (Hash)

    Request parameter options for notification index

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load notification index by their status (Nothing as auto, ‘opened’ or ‘unopened’)

  • :limit (String) — default: nil

    Maximum number of notifications to return

  • :reverse (String) — default: 'false'

    Whether notification index will be ordered as earliest first

  • :without_grouping (String) — default: 'false'

    Whether notification index will include group members

  • :with_group_members (String) — default: 'false'

    Whether notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type to filter notification index

  • :filtered_by_group_type (String) — default: nil

    Group type to filter notification index, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance ID to filter notification index, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of notifications to filter notification index

  • :later_than (String) — default: nil

    ISO 8601 format time to filter notification index later than specified time

  • :earlier_than (String) — default: nil

    ISO 8601 format time to filter notification index earlier than specified time

Returns:

  • (JSON)

    count: number of notification index records, notifications: notification index



28
29
30
31
32
33
34
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 28

def index
  super
  render json: {
    count: @notifications.size, 
    notifications: @notifications.as_json(notification_json_options)
  }
end

#open(params) ⇒ JSON

Moves to notifiable_path of the notification.

GET /:target_type/:target_id/notifications/:id/move

Returns location: notifiable path, count: number of opened notification records, notification: specified notification.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :open (String) — default: 'false'

    Whether the notification will be opened

Returns:

  • (JSON)

    location: notifiable path, count: number of opened notification records, notification: specified notification



124
125
126
127
128
129
130
131
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 124

def move
  super
  render status: 302, location: @notification.notifiable_path, json: {
    location: @notification.notifiable_path,
    count: (@opened_notifications_count || 0),
    notification: notification_json
  }
end

#open(params) ⇒ JSON

Opens a notification.

PUT /:target_type/:target_id/notifications/:id/open

Returns count: number of opened notification records, notification: opened notification.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :move (String) — default: 'false'

    Whether it redirects to notifiable_path after the notification is opened

Returns:

  • (JSON)

    count: number of opened notification records, notification: opened notification



107
108
109
110
111
112
113
114
115
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 107

def open
  super
  unless params[:move].to_s.to_boolean(false)
    render json: {
      count: @opened_notifications_count,
      notification: notification_json
    }
  end
end

#open_all(params) ⇒ JSON

Opens all notifications of the target.

POST /:target_type/:target_id/notifications/open_all

Returns count: number of opened notification records, notifications: opened notifications.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filtered_by_type (String) — default: nil

    Notifiable type to filter notification index

  • :filtered_by_group_type (String) — default: nil

    Group type to filter notification index, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance ID to filter notification index, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of notifications to filter notification index

  • :later_than (String) — default: nil

    ISO 8601 format time to filter notification index later than specified time

  • :earlier_than (String) — default: nil

    ISO 8601 format time to filter notification index earlier than specified time

  • :ids (Array) — default: nil

    Array of specific notification IDs to open

Returns:

  • (JSON)

    count: number of opened notification records, notifications: opened notifications



49
50
51
52
53
54
55
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 49

def open_all
  super
  render json: {
    count: @opened_notifications.size,
    notifications: @opened_notifications.as_json(notification_json_options)
  }
end

#show(params) ⇒ JSON

Returns a single notification.

GET /:target_type/:target_id/notifications/:id

Returns Found single notification.

Parameters:

  • params (Hash)

    Request parameters

Returns:

  • (JSON)

    Found single notification



84
85
86
87
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 84

def show
  super
  render json: notification_json
end