2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-06 17:16:02 +02:00
|
|
|
class DataSources::ChorusController < ApplicationController
|
|
|
|
before_action :authenticate_administrateur!
|
|
|
|
|
|
|
|
def search_domaine_fonct
|
2023-10-19 15:19:23 +02:00
|
|
|
result_json = APIBretagneService.new.search_domaine_fonct(code_or_label: params[:q])
|
|
|
|
render json: format_result(result_json:,
|
|
|
|
label_formatter: ChorusConfiguration.method(:format_domaine_fonctionnel_label))
|
2023-09-06 17:16:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def search_centre_couts
|
2023-10-19 15:19:23 +02:00
|
|
|
result_json = APIBretagneService.new.search_centre_couts(code_or_label: params[:q])
|
|
|
|
render json: format_result(result_json:,
|
2023-11-09 09:59:04 +01:00
|
|
|
label_formatter: ChorusConfiguration.method(:format_centre_de_cout_label))
|
2023-09-06 17:16:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def search_ref_programmation
|
2023-10-19 15:19:23 +02:00
|
|
|
result_json = APIBretagneService.new.search_ref_programmation(code_or_label: params[:q])
|
|
|
|
render json: format_result(result_json:,
|
|
|
|
label_formatter: ChorusConfiguration.method(:format_ref_programmation_label))
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def format_result(result_json:, label_formatter:)
|
|
|
|
result_json.map do |item|
|
2023-09-06 17:16:02 +02:00
|
|
|
{
|
2023-10-19 15:19:23 +02:00
|
|
|
label: label_formatter.call(item),
|
2023-11-09 09:59:04 +01:00
|
|
|
value: item[:code],
|
2023-09-06 17:16:02 +02:00
|
|
|
data: item
|
|
|
|
}
|
|
|
|
end
|
2023-10-19 15:19:23 +02:00
|
|
|
end
|
2023-09-06 17:16:02 +02:00
|
|
|
end
|