From a98fbab424249e469e7711dcb7661612e358dd6f Mon Sep 17 00:00:00 2001 From: Osama Sayed Date: Thu, 13 Jun 2024 19:53:12 +0300 Subject: [PATCH 1/2] Only load approved Word-by-Word translations --- app/finders/qdc/verse_finder.rb | 5 +++-- app/finders/v4/verse_finder.rb | 3 ++- app/finders/verse_finder.rb | 5 +++-- app/models/resource_content.rb | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/finders/qdc/verse_finder.rb b/app/finders/qdc/verse_finder.rb index 5c033cf6..cd7167c5 100644 --- a/app/finders/qdc/verse_finder.rb +++ b/app/finders/qdc/verse_finder.rb @@ -239,13 +239,14 @@ def load_words(word_translation_lang, mushaf) language = Language.find_with_id_or_iso_code(word_translation_lang) @results = @results.where(mushaf_words: { mushaf_id: mushaf.id }) - words_with_default_translation = @results.where(word_translations: { language_id: Language.default.id }) + approved_word_by_word_translations = ResourceContent.approved.one_word.translations + words_with_default_translation = @results.where(word_translations: { language_id: Language.default.id, resource_content_id: approved_word_by_word_translations }) if language.nil? || language.default? @results = words_with_default_translation.eager_load(mushaf_words: eager_load_words) else @results = @results - .where(word_translations: { language_id: language.id }) + .where(word_translations: { language_id: language.id, resource_content_id: approved_word_by_word_translations }) .or(words_with_default_translation) .eager_load(mushaf_words: eager_load_words) end diff --git a/app/finders/v4/verse_finder.rb b/app/finders/v4/verse_finder.rb index 90ddbf68..4f9622c4 100644 --- a/app/finders/v4/verse_finder.rb +++ b/app/finders/v4/verse_finder.rb @@ -185,11 +185,12 @@ def verse_pagination_end(start, total_verses) def load_words(word_translation_lang) language = Language.find_with_id_or_iso_code(word_translation_lang) + approved_word_by_word_translations = ResourceContent.approved.one_word.translations words_with_default_translation = @results.where(word_translations: { language_id: Language.default.id }) if language @results = @results - .where(word_translations: { language_id: language.id }) + .where(word_translations: { language_id: language.id, resource_content_id: approved_word_by_word_translations }) .or(words_with_default_translation) .eager_load(words: eager_load_words) else diff --git a/app/finders/verse_finder.rb b/app/finders/verse_finder.rb index e9a93b73..26aaebbe 100644 --- a/app/finders/verse_finder.rb +++ b/app/finders/verse_finder.rb @@ -52,11 +52,12 @@ def fetch_verses_range def load_words(word_translation_lang) language = Language.find_with_id_or_iso_code(word_translation_lang) - words_with_default_translation = results.where(word_translations: { language_id: Language.default.id }) + approved_word_by_word_translations = ResourceContent.approved.one_word.translations + words_with_default_translation = results.where(word_translations: { language_id: Language.default.id, resource_content_id: approved_word_by_word_translations }) if language @results = @results - .where(word_translations: { language_id: language.id }) + .where(word_translations: { language_id: language.id, resource_content_id: approved_word_by_word_translations }) .or(words_with_default_translation) .eager_load(words: eager_load_words) else diff --git a/app/models/resource_content.rb b/app/models/resource_content.rb index 2ac41dd1..d90553ca 100644 --- a/app/models/resource_content.rb +++ b/app/models/resource_content.rb @@ -44,10 +44,12 @@ class ResourceContent < ApplicationRecord scope :translations, -> { where sub_type: [SubType::Translation, SubType::Transliteration] } scope :media, -> { where sub_type: SubType::Video } + scope :translations, -> { where sub_type: SubType::Translation } scope :tafsirs, -> { where sub_type: SubType::Tafsir } scope :chapter_info, -> { where sub_type: SubType::Info } scope :one_verse, -> { where cardinality_type: CardinalityType::OneVerse } scope :one_chapter, -> { where cardinality_type: CardinalityType::OneChapter } + scope :one_word, -> { where cardinality_type: CardinalityType::OneWord } scope :approved, -> { where approved: true } scope :recitations, -> { where sub_type: SubType::Audio } From 2ea98186b79f25ba713da9df3bfb939bea59e22b Mon Sep 17 00:00:00 2001 From: Osama Sayed Date: Thu, 13 Jun 2024 21:15:28 +0300 Subject: [PATCH 2/2] List word by word translations resources API --- .../api/qdc/resources_controller.rb | 8 +++++++ .../api/v4/resources_controller.rb | 8 +++++++ .../word_by_word_translations.json.streamer | 22 +++++++++++++++++++ .../word_by_word_translations.json.streamer | 22 +++++++++++++++++++ config/routes/api/qdc.rb | 1 + config/routes/api/v4.rb | 1 + 6 files changed, 62 insertions(+) create mode 100644 app/views/api/qdc/resources/word_by_word_translations.json.streamer create mode 100644 app/views/api/v4/resources/word_by_word_translations.json.streamer diff --git a/app/controllers/api/qdc/resources_controller.rb b/app/controllers/api/qdc/resources_controller.rb index 206ef4ff..115db81d 100644 --- a/app/controllers/api/qdc/resources_controller.rb +++ b/app/controllers/api/qdc/resources_controller.rb @@ -40,6 +40,14 @@ def tafsirs render end + def word_by_word_translations + list = ResourceContent.eager_load(:translated_name).approved.one_word.translations.order('priority ASC') + + @word_by_word_translations = eager_load_translated_name(list) + + render + end + def tafsir_info if @tafsir = fetch_tafsir_resource render diff --git a/app/controllers/api/v4/resources_controller.rb b/app/controllers/api/v4/resources_controller.rb index da0c62bd..6416954c 100644 --- a/app/controllers/api/v4/resources_controller.rb +++ b/app/controllers/api/v4/resources_controller.rb @@ -30,6 +30,14 @@ def translation_info end end + def word_by_word_translations + list = ResourceContent.eager_load(:translated_name).approved.one_word.translations.order('priority ASC') + + @word_by_word_translations = eager_load_translated_name(list) + + render + end + def tafsirs list = ResourceContent .eager_load(:translated_name) diff --git a/app/views/api/qdc/resources/word_by_word_translations.json.streamer b/app/views/api/qdc/resources/word_by_word_translations.json.streamer new file mode 100644 index 00000000..10df5f47 --- /dev/null +++ b/app/views/api/qdc/resources/word_by_word_translations.json.streamer @@ -0,0 +1,22 @@ +json.object! do + json.word_by_word_translations do + json.array! @word_by_word_translations do |word_by_word_translation| + json.object! do + json.extract! word_by_word_translation, + :id, + :name, + :author_name, + :slug, + :language_name + json.iso_code word_by_word_translation.language.iso_code + + json.translated_name do + translated_name = word_by_word_translation.translated_name + json.object! do + json.extract! translated_name, :name, :language_name + end + end + end + end + end +end diff --git a/app/views/api/v4/resources/word_by_word_translations.json.streamer b/app/views/api/v4/resources/word_by_word_translations.json.streamer new file mode 100644 index 00000000..10df5f47 --- /dev/null +++ b/app/views/api/v4/resources/word_by_word_translations.json.streamer @@ -0,0 +1,22 @@ +json.object! do + json.word_by_word_translations do + json.array! @word_by_word_translations do |word_by_word_translation| + json.object! do + json.extract! word_by_word_translation, + :id, + :name, + :author_name, + :slug, + :language_name + json.iso_code word_by_word_translation.language.iso_code + + json.translated_name do + translated_name = word_by_word_translation.translated_name + json.object! do + json.extract! translated_name, :name, :language_name + end + end + end + end + end +end diff --git a/config/routes/api/qdc.rb b/config/routes/api/qdc.rb index 1c44a052..ea0ff2c0 100644 --- a/config/routes/api/qdc.rb +++ b/config/routes/api/qdc.rb @@ -27,6 +27,7 @@ get :languages get :chapter_infos get :verse_media + get :word_by_word_translations end get :chapters, to: 'chapters#index' diff --git a/config/routes/api/v4.rb b/config/routes/api/v4.rb index f9155312..ec6fdec7 100644 --- a/config/routes/api/v4.rb +++ b/config/routes/api/v4.rb @@ -78,6 +78,7 @@ get :verse_media get :chapter_reciters get :changes + get :word_by_word_translations end # routes for fetching all records of one resource.