2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-10-13 16:06:26 +02:00
|
|
|
class DataSources::CommuneController < ApplicationController
|
|
|
|
def search
|
|
|
|
if params[:q].present? && params[:q].length > 1
|
2024-09-05 17:50:32 +02:00
|
|
|
response = APIGeoService.commune_by_name_or_postal_code(params[:q])
|
2023-10-13 16:06:26 +02:00
|
|
|
|
|
|
|
if response.success?
|
|
|
|
results = JSON.parse(response.body, symbolize_names: true)
|
|
|
|
|
2024-09-05 17:50:32 +02:00
|
|
|
render json: APIGeoService.format_commune_response(results, params[:with_combined_code])
|
2023-10-13 16:06:26 +02:00
|
|
|
else
|
|
|
|
render json: []
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render json: []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|