Skip to content

Commit

Permalink
fix: fixed logic getting preferences for country and language
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinayoob committed Sep 23, 2024
1 parent fc8e087 commit 4faac26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
11 changes: 6 additions & 5 deletions app/controllers/api/qdc/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ def country_language_preference
country = request.query_parameters[:country]

if user_device_language.blank?
render json: { error: 'user_device_language is required' }, status: :bad_request
return
return render_bad_request('user_device_language is required')
end

preferences = CountryLanguagePreference.where(user_device_language: user_device_language)
preferences = preferences.where(country: [country, nil]) if country.present?
if country.blank?
return render_bad_request('country is required')
end

@preference = preferences.first
preferences = CountryLanguagePreference.where(user_device_language: user_device_language, country: country)
@preference = preferences.first || CountryLanguagePreference.find_by(user_device_language: user_device_language, country: nil)

if @preference
load_default_resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,55 @@ json.object! do

json.default_mushaf do
json.object! do
json.extract! @data[:default_mushaf], :id, :name if @data[:default_mushaf]
json.extract! @data[:default_mushaf], :id, :name
end
end

json.default_translations do
json.array! do
json.array! @data[:default_translations] do |translation|
json.object! do
json.extract! translation, :id, :name, :author_name, :slug, :language_name
json.translated_name do
translated_name = translation.translated_name
json.object! do
json.extract! translated_name, :name, :language_name
end
json.array! @data[:default_translations] do |translation|
json.object! do
json.extract! translation, :id, :name, :author_name, :slug, :language_name
json.translated_name do
translated_name = translation.translated_name
json.object! do
json.extract! translated_name, :name, :language_name
end
end
end
end
end if @data[:default_translations].present?
end
end

json.default_tafsir do
json.object! do
json.extract! @data[:default_tafsir], :id, :name, :author_name if @data[:default_tafsir]
json.extract! @data[:default_tafsir], :id, :name, :author_name
end
end

json.default_wbw_language do
json.object! do
json.extract! @data[:default_wbw_language], :id, :name, :iso_code if @data[:default_wbw_language]
json.extract! @data[:default_wbw_language], :id, :name, :iso_code
end
end

json.default_reciter do
json.object! do
json.extract! @data[:default_reciter], :id, :name if @data[:default_reciter]
json.extract! @data[:default_reciter], :id, :name
end
end

json.ayah_reflections_languages do
json.array! do
json.array! @data[:ayah_reflections_languages] do |language|
json.object! do
json.extract! language, :id, :name, :iso_code
end
json.array! @data[:ayah_reflections_languages] do |language|
json.object! do
json.extract! language, :id, :name, :iso_code
end
end
end if @data[:ayah_reflections_languages].present?
end

json.learning_plan_languages do
json.array! do
json.array! @data[:learning_plan_languages] do |language|
json.object! do
json.extract! language, :id, :name, :iso_code
end
json.array! @data[:learning_plan_languages] do |language|
json.object! do
json.extract! language, :id, :name, :iso_code
end
end
end if @data[:learning_plan_languages].present?
end
end

0 comments on commit 4faac26

Please sign in to comment.