Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
3 changes: 1 addition & 2 deletions app/controllers/v3/verses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: '**'
Expand Down Expand Up @@ -65,7 +65,6 @@ def render_media?

def word_includes
[
:char_type,
:audio,
eager_language('translations'),
eager_language('transliterations')
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/v3/translation_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
#

class V3::TranslationSerializer < V3::ApplicationSerializer
attributes :language_name, :text, :resource_name
attributes :id, :language_name, :text, :resource_name
end
9 changes: 3 additions & 6 deletions app/serializers/v3/word_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170326214632_add_char_type_name_to_words.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCharTypeNameToWords < ActiveRecord::Migration[5.0]
def change
add_column :words, :char_type_name, :string
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -653,15 +653,16 @@
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"
t.string "image_url"
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
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/v3.rake
Original file line number Diff line number Diff line change
@@ -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',
Expand Down