Created
February 9, 2017 20:10
-
-
Save richmolj/b8f7bf8952641acc3beab07f3afc742c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContractsController | |
jsonapi resource: ContractResource | |
end | |
class TransactionsController | |
jsonapi resource: TransactionResource | |
end | |
class ContractResource < JsonapiCompliable::Resource | |
type :contracts | |
use_adapter JsonapiCompliable::Adapters::ActiveRecord | |
has_many :transactions, | |
foreign_key: :contract_id, | |
scope: -> { Transaction.all }, | |
resource: TransactionResource | |
polymorphic_belongs_to :workspace, | |
group_by: proc { |contract| contract.workspace_type }, | |
groups: { | |
'SpecialWorkspace' => { | |
resource: WorkspaceResource | |
}, | |
'AnotherSpecialWorkspace' => { | |
resource: WorkspaceResource | |
| | |
} | |
end | |
class TransactionResource < JsonapiCompliable::Resource | |
type :transactions | |
end | |
allow_sideload :workspace, resource: WorkspaceResource do | |
scope do |contracts| | |
BasService.call({ 'Filter' => { 'ContractIDs' => contracts.map(&:id) } }) | |
end | |
assign do |contracts, transactions| | |
contracts. | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment