Class: Spree::Api::V2::Tenant::NotificationsController
- Inherits:
-
BaseController
- Object
- ResourceController
- BaseController
- Spree::Api::V2::Tenant::NotificationsController
show all
- Defined in:
- app/controllers/spree/api/v2/tenant/notifications_controller.rb
Instance Method Summary
collapse
#render_serialized_payload, #require_tenant, #scope
Instance Method Details
#collection ⇒ Object
8
9
10
|
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 8
def collection
spree_current_user.notifications.newest_first.user_notifications
end
|
#collection_serializer ⇒ Object
#mark_all_as_read ⇒ Object
36
37
38
39
40
41
42
|
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 36
def mark_all_as_read
result = SpreeCmCommissioner::NotificationReader.call(user: spree_current_user)
return unless result.success?
head :ok
end
|
#mark_as_read ⇒ Object
28
29
30
31
32
33
34
|
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 28
def mark_as_read
result = SpreeCmCommissioner::NotificationReader.call(id: params[:id])
return unless result.success?
head :ok
end
|
#resource_serializer ⇒ Object
#serialize_collection(collection) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 12
def serialize_collection(collection)
options_data = collection_options(collection).merge(params: serializer_params)
options_data[:meta][:unread_count] = collection.select(&:unread?).count
collection_serializer.new(
collection,
options_data
).serializable_hash
end
|
#show ⇒ Object
22
23
24
25
26
|
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 22
def show
notification = SpreeCmCommissioner::Notification.find(params[:id])
render_serialized_payload { serialize_resource(notification) }
end
|