Class: Spree::Api::V2::Storefront::NotificationsController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/spree/api/v2/storefront/notifications_controller.rb

Direct Known Subclasses

OrderRequestNotificationsController

Instance Method Summary collapse

Instance Method Details

#collectionObject



8
9
10
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 8

def collection
  spree_current_user.notifications.newest_first.user_notifications
end

#collection_serializerObject



22
23
24
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 22

def collection_serializer
  Spree::V2::Storefront::NotificationSerializer
end

#mark_all_as_readObject



40
41
42
43
44
45
46
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 40

def mark_all_as_read
  result = SpreeCmCommissioner::NotificationReader.call(user: spree_current_user)

  return unless result.success?

  head :ok
end

#mark_as_readObject



32
33
34
35
36
37
38
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 32

def mark_as_read
  result = SpreeCmCommissioner::NotificationReader.call(id: params[:id])

  return unless result.success?

  head :ok
end

#resource_serializerObject



48
49
50
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 48

def resource_serializer
  Spree::V2::Storefront::NotificationSerializer
end

#serialize_collection(collection) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'app/controllers/spree/api/v2/storefront/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

#showObject



26
27
28
29
30
# File 'app/controllers/spree/api/v2/storefront/notifications_controller.rb', line 26

def show
  notification = SpreeCmCommissioner::Notification.find(params[:id])

  render_serialized_payload { serialize_resource(notification) }
end