Class: Decidim::Core::ParticipatorySpaceListBase

Inherits:
Object
  • Object
show all
Includes:
NeedsApiDefaultOrder, NeedsApiFilterAndOrder
Defined in:
decidim-core/lib/decidim/api/functions/participatory_space_list_base.rb

Overview

An abstract base class resolver for the GraphQL endpoint for listing participatory spaces Inherit from this class and add search arguments to create list-finders participatory classes as is shown in ParticipatorySpaceList + info: github.com/rmosolgo/graphql-ruby/blob/v1.6.8/guides/fields/function.md

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NeedsApiFilterAndOrder

#add_filter_keys, #add_order_keys

Constructor Details

#initialize(manifest:) ⇒ ParticipatorySpaceListBase

Returns a new instance of ParticipatorySpaceListBase.


15
16
17
# File 'decidim-core/lib/decidim/api/functions/participatory_space_list_base.rb', line 15

def initialize(manifest:)
  @manifest = manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest


13
14
15
# File 'decidim-core/lib/decidim/api/functions/participatory_space_list_base.rb', line 13

def manifest
  @manifest
end

Instance Method Details

#call(_obj, args, ctx) ⇒ Object


24
25
26
27
28
29
30
31
32
33
# File 'decidim-core/lib/decidim/api/functions/participatory_space_list_base.rb', line 24

def call(_obj, args, ctx)
  @query = model_class.public_spaces.where(
    organization: ctx[:current_organization]
  )

  add_filter_keys(args[:filter])
  add_order_keys(args[:order].to_h)
  add_default_order
  @query
end

#model_classObject

lazy instantation of the class


20
21
22
# File 'decidim-core/lib/decidim/api/functions/participatory_space_list_base.rb', line 20

def model_class
  @model_class ||= manifest.model_class_name.constantize
end