diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 57e76627..9181df6b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::API class APIValidation < StandardError; end rescue_from APIValidation, with: :throw_the_error + before_action :set_cache_headers private @@ -14,4 +15,8 @@ def throw_the_error(error) def eager_language(type) "#{params[:language] || 'en'}_#{type}".to_sym end + + def set_cache_headers + expires_in 1.day, public: true + end end diff --git a/app/controllers/v3/verses_controller.rb b/app/controllers/v3/verses_controller.rb index 27ea55ba..e317d22c 100644 --- a/app/controllers/v3/verses_controller.rb +++ b/app/controllers/v3/verses_controller.rb @@ -16,7 +16,7 @@ def show chapter = Chapter.find(params[:chapter_id]) verse = chapter .verses - .includes(words: [:char_type, :audio]) + .includes(words: [:audio]) .find(params[:id]) render json: verse, include: '**' @@ -65,7 +65,6 @@ def render_media? def word_includes [ - :char_type, :audio, eager_language('translations'), eager_language('transliterations') diff --git a/app/serializers/v3/translation_serializer.rb b/app/serializers/v3/translation_serializer.rb index 1bf8f9fc..802dd9c8 100644 --- a/app/serializers/v3/translation_serializer.rb +++ b/app/serializers/v3/translation_serializer.rb @@ -13,5 +13,5 @@ # class V3::TranslationSerializer < V3::ApplicationSerializer - attributes :language_name, :text, :resource_name + attributes :id, :language_name, :text, :resource_name end diff --git a/app/serializers/v3/word_serializer.rb b/app/serializers/v3/word_serializer.rb index 006070ba..69379bfd 100644 --- a/app/serializers/v3/word_serializer.rb +++ b/app/serializers/v3/word_serializer.rb @@ -29,8 +29,9 @@ class V3::WordSerializer < V3::ApplicationSerializer :line_number, :page_number, :code, - :code_v3, - :char_type + :code_v3 + + attribute :char_type_name, key: :char_type has_one :audio, serializer: V3::AudioFileSerializer @@ -46,10 +47,6 @@ class V3::WordSerializer < V3::ApplicationSerializer transliteration.present? ? transliteration : object.en_transliterations.first end - def char_type - object.char_type.name - end - def class_name "p#{object.page_number}" end diff --git a/db/migrate/20170326214632_add_char_type_name_to_words.rb b/db/migrate/20170326214632_add_char_type_name_to_words.rb new file mode 100644 index 00000000..a3fae331 --- /dev/null +++ b/db/migrate/20170326214632_add_char_type_name_to_words.rb @@ -0,0 +1,5 @@ +class AddCharTypeNameToWords < ActiveRecord::Migration[5.0] + def change + add_column :words, :char_type_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 355f56b6..e3c3e6a7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170301004755) do +ActiveRecord::Schema.define(version: 20170326214632) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -653,8 +653,8 @@ t.string "code_hex_v3" t.integer "code_dec_v3" t.integer "char_type_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "pause_name" t.string "audio_url" t.text "image_blob" @@ -662,6 +662,7 @@ t.string "location" t.integer "topic_id" t.integer "token_id" + t.string "char_type_name" t.index ["chapter_id"], name: "index_words_on_chapter_id", using: :btree t.index ["char_type_id"], name: "index_words_on_char_type_id", using: :btree t.index ["location"], name: "index_words_on_location", using: :btree diff --git a/lib/tasks/v3.rake b/lib/tasks/v3.rake index a36c02a7..14f04f63 100644 --- a/lib/tasks/v3.rake +++ b/lib/tasks/v3.rake @@ -1,4 +1,10 @@ namespace :v3 do + task fix_char_type_name: :environment do + CharType.all.each do |char_type| + Word.where(char_type: char_type).update_all char_type_name: char_type.name + end + end + task remove_v2_tables: :environment do ['file', 'recitation', 'reciter', 'style', 'author', 'resource', 'resource_api_version', 'source', 'surah_infos', 'tafsir', 'tafsir_ayah', 'translation', 'transliteration', 'language', 'media.content', 'media.resource',