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



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

def destroy
  super
  head 204
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



102
103
104
105
106
107
108
109
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 102

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



85
86
87
88
89
90
91
92
93
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 85

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

Returns:

  • (JSON)

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



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

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



62
63
64
65
# File 'app/controllers/activity_notification/notifications_api_controller.rb', line 62

def show
  super
  render json: notification_json
end