Class: CommandTower::InboxService::Message::Metadata

Inherits:
ServiceBase
  • Object
show all
Includes:
PaginationServiceHelper
Defined in:
app/services/command_tower/inbox_service/message/metadata.rb

Constant Summary

Constants inherited from ServiceBase

ServiceBase::ON_ARGUMENT_VALIDATION

Instance Method Summary collapse

Methods included from PaginationServiceHelper

#pagination_cursor, #pagination_limit, #pagination_page, #pagination_params, #pagination_schema, #query

Methods inherited from ServiceBase

inherited, #internal_validate, #service_base_logging, #validate!

Methods included from ArgumentValidation

included

Methods included from ServiceLogging

#aletered_message, #class_name, #log, #log_error, #log_info, #log_prefix, #log_warn, #logger, #service_id

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/command_tower/inbox_service/message/metadata.rb', line 13

def call
  entities = query.map do |message|
    CommandTower::Schema::Inbox::MessageEntity.new(
      id: message.id,
      title: message.title,
      viewed: message.viewed,
    )
  end

  params = {
    count: entities.length,
    entities: entities.nil? ? nil : entities,
    pagination: pagination_schema,
  }.compact
  context. = CommandTower::Schema::Inbox::Metadata.new(**params)
end

#default_queryObject



30
31
32
# File 'app/services/command_tower/inbox_service/message/metadata.rb', line 30

def default_query
  ::Message.where(user:).select(:id, :title, :viewed)
end