You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
1009 B

module Api
module Jurisprudence
class CrossReferencesController < ::Api::BaseController
load_resource :document, class: "Cdao::Jurisprudence", id_param: :jurisprudence_id
def index
authorize! :read, @document
response = { data: [] }
document = @document
where = { enabled: true, state: "published" }
document.class.cited_docs_of(document, where).group_by { |a| a.class.name }.each do |klass, docs|
klass = klass.gsub("Cdao::", "")
library = Cdao::Library.find_by(document_type: klass)
response[:data] << {
library: {
document_type: klass,
display_name: library.try(:display_name).presence || "",
name: library.try(:name).presence || "",
},
data_id_prefix: "#{klass}-",
documents: docs.map { |doc| doc.to_builder(current_ability).attributes! }
}
end
render json: response
end
end
end
end