Class: Spree::Api::V2::Tenant::NotificationsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#render_serialized_payload, #require_tenant, #scope

Instance Method Details

#collectionObject



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_serializerObject



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

def collection_serializer
  Spree::V2::Tenant::NotificationSerializer
end

#mark_all_as_readObject



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_readObject



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_serializerObject



44
45
46
# File 'app/controllers/spree/api/v2/tenant/notifications_controller.rb', line 44

def resource_serializer
  Spree::V2::Tenant::NotificationSerializer
end

#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

#showObject



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