Class: ForestAdminAgent::Routes::Resources::Show
- Inherits:
-
AbstractAuthenticatedRoute
- Object
- AbstractRoute
- AbstractAuthenticatedRoute
- ForestAdminAgent::Routes::Resources::Show
- Defined in:
- lib/forest_admin_agent/routes/resources/show.rb
Instance Method Summary collapse
Methods inherited from AbstractAuthenticatedRoute
#build, #format_attributes, #redacted_full_projection, #redacted_projection_with_pks
Methods inherited from AbstractRoute
#add_route, #build, #initialize, #routes
Constructor Details
This class inherits a constructor from ForestAdminAgent::Routes::AbstractRoute
Instance Method Details
#handle_request(args = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/forest_admin_agent/routes/resources/show.rb', line 18 def handle_request(args = {}) context = build(args) context..can?(:read, context.collection) scope = context..get_scope(context.collection) primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true) condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values]) filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new( condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope]) ) projection = redacted_projection_with_pks(context, context.collection, args) records = context.collection.list(context.caller, filter, projection) raise Http::Exceptions::NotFoundError, 'Record does not exists' unless records.size.positive? { name: args[:params]['collection_name'], content: JSONAPI::Serializer.serialize( records[0], class_name: context.collection.name, is_collection: false, serializer: Serializer::ForestSerializer, include: projection.relation_include_paths ) } end |
#setup_routes ⇒ Object
12 13 14 15 16 |
# File 'lib/forest_admin_agent/routes/resources/show.rb', line 12 def setup_routes add_route('forest_show', 'get', '/:collection_name/:id', ->(args) { handle_request(args) }) self end |