From 7f68a83adec26372f38153f6ba1dc94aa2abf3b7 Mon Sep 17 00:00:00 2001 From: Dilraj Date: Wed, 14 Feb 2024 01:58:15 -0500 Subject: [PATCH 1/4] Random old changes --- app/controllers/books_controller.rb | 1 + app/models/chapter.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index d6eb11d..6fab66d 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class BooksController < ApplicationController + # NOTE: Remember to see .jbuilder def index @books = Book.all end diff --git a/app/models/chapter.rb b/app/models/chapter.rb index d0e68f4..696ed05 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -43,6 +43,18 @@ def copy_paste_info Rails.logger.debug info end + def copy_paste_artwork_alt_text + info = <<~HEREDOC + {https://spg.dev/chapters/#{self.id}} + + Artwork for chapter #{self.number} of #{self.book.en_title}, titled: “#{self.en_title}.” + + #{self.en_short_summary} + HEREDOC + + Rails.logger.debug info + end + def csv_rows file_path = "lib/imports/#{self.book.sequence}/#{self.number}.csv" From a07fe82ed234bd39f4c0e277fafef2f3d09113cd Mon Sep 17 00:00:00 2001 From: Dilraj Date: Wed, 14 Feb 2024 01:58:40 -0500 Subject: [PATCH 2/4] Add `slug` to `Book` model --- app/views/books/index.json.jbuilder | 2 +- .../20240214064320_add_slug_to_books.rb | 39 +++++++++++++++++++ db/schema.rb | 4 +- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240214064320_add_slug_to_books.rb diff --git a/app/views/books/index.json.jbuilder b/app/views/books/index.json.jbuilder index ed103ef..1e0c869 100644 --- a/app/views/books/index.json.jbuilder +++ b/app/views/books/index.json.jbuilder @@ -3,5 +3,5 @@ json.key_format! :camelize => :lower json.books do - json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released) + json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released, :slug) end diff --git a/db/migrate/20240214064320_add_slug_to_books.rb b/db/migrate/20240214064320_add_slug_to_books.rb new file mode 100644 index 0000000..438a782 --- /dev/null +++ b/db/migrate/20240214064320_add_slug_to_books.rb @@ -0,0 +1,39 @@ +class AddSlugToBooks < ActiveRecord::Migration[7.0] + def change + add_column :books, :slug, :string + add_index :books, :slug, :unique => true + + reversible do |dir| + dir.up do + slug_mappings = [ + { :id => 1, :slug => 'nanak-prakash-purbardh' }, + { :id => 2, :slug => 'nanak-prakash-utrardh' }, + { :id => 3, :slug => 'raas-1' }, + { :id => 4, :slug => 'raas-2' }, + { :id => 5, :slug => 'raas-3' }, + { :id => 6, :slug => 'raas-4' }, + { :id => 7, :slug => 'raas-5' }, + { :id => 8, :slug => 'raas-6' }, + { :id => 9, :slug => 'raas-7' }, + { :id => 10, :slug => 'raas-8' }, + { :id => 11, :slug => 'raas-9' }, + { :id => 12, :slug => 'raas-10' }, + { :id => 13, :slug => 'raas-11' }, + { :id => 14, :slug => 'raas-12' }, + { :id => 15, :slug => 'rut-1' }, + { :id => 16, :slug => 'rut-2' }, + { :id => 17, :slug => 'rut-3' }, + { :id => 18, :slug => 'rut-4' }, + { :id => 19, :slug => 'rut-5' }, + { :id => 20, :slug => 'rut-6' }, + { :id => 21, :slug => 'ayaan-1' }, + { :id => 22, :slug => 'ayaan-2' } + ] + + slug_mappings.each do |mapping| + Book.find_by(:id => mapping[:id])&.update(:slug => mapping[:slug]) + end + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 03777dd..71c6642 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[7.0].define(version: 2023_06_11_191536) do +ActiveRecord::Schema[7.0].define(version: 2024_02_14_064320) do create_table "books", force: :cascade do |t| t.integer "sequence", null: false t.string "title", null: false @@ -20,6 +20,8 @@ t.text "artwork_url" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug" + t.index ["slug"], name: "index_books_on_slug", unique: true end create_table "chapter_kathas", force: :cascade do |t| From 036ae2ca46c4551fe131c2dac575f1e6b331379e Mon Sep 17 00:00:00 2001 From: Dilraj Somel Date: Wed, 14 Feb 2024 02:03:04 -0500 Subject: [PATCH 3/4] Lint --- .../20240214064320_add_slug_to_books.rb | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/db/migrate/20240214064320_add_slug_to_books.rb b/db/migrate/20240214064320_add_slug_to_books.rb index 438a782..3ff00cf 100644 --- a/db/migrate/20240214064320_add_slug_to_books.rb +++ b/db/migrate/20240214064320_add_slug_to_books.rb @@ -1,35 +1,37 @@ +# frozen_string_literal: true + class AddSlugToBooks < ActiveRecord::Migration[7.0] def change add_column :books, :slug, :string add_index :books, :slug, :unique => true + slug_mappings = [ + { :id => 1, :slug => 'nanak-prakash-purbardh' }, + { :id => 2, :slug => 'nanak-prakash-utrardh' }, + { :id => 3, :slug => 'raas-1' }, + { :id => 4, :slug => 'raas-2' }, + { :id => 5, :slug => 'raas-3' }, + { :id => 6, :slug => 'raas-4' }, + { :id => 7, :slug => 'raas-5' }, + { :id => 8, :slug => 'raas-6' }, + { :id => 9, :slug => 'raas-7' }, + { :id => 10, :slug => 'raas-8' }, + { :id => 11, :slug => 'raas-9' }, + { :id => 12, :slug => 'raas-10' }, + { :id => 13, :slug => 'raas-11' }, + { :id => 14, :slug => 'raas-12' }, + { :id => 15, :slug => 'rut-1' }, + { :id => 16, :slug => 'rut-2' }, + { :id => 17, :slug => 'rut-3' }, + { :id => 18, :slug => 'rut-4' }, + { :id => 19, :slug => 'rut-5' }, + { :id => 20, :slug => 'rut-6' }, + { :id => 21, :slug => 'ayaan-1' }, + { :id => 22, :slug => 'ayaan-2' } + ] + reversible do |dir| dir.up do - slug_mappings = [ - { :id => 1, :slug => 'nanak-prakash-purbardh' }, - { :id => 2, :slug => 'nanak-prakash-utrardh' }, - { :id => 3, :slug => 'raas-1' }, - { :id => 4, :slug => 'raas-2' }, - { :id => 5, :slug => 'raas-3' }, - { :id => 6, :slug => 'raas-4' }, - { :id => 7, :slug => 'raas-5' }, - { :id => 8, :slug => 'raas-6' }, - { :id => 9, :slug => 'raas-7' }, - { :id => 10, :slug => 'raas-8' }, - { :id => 11, :slug => 'raas-9' }, - { :id => 12, :slug => 'raas-10' }, - { :id => 13, :slug => 'raas-11' }, - { :id => 14, :slug => 'raas-12' }, - { :id => 15, :slug => 'rut-1' }, - { :id => 16, :slug => 'rut-2' }, - { :id => 17, :slug => 'rut-3' }, - { :id => 18, :slug => 'rut-4' }, - { :id => 19, :slug => 'rut-5' }, - { :id => 20, :slug => 'rut-6' }, - { :id => 21, :slug => 'ayaan-1' }, - { :id => 22, :slug => 'ayaan-2' } - ] - slug_mappings.each do |mapping| Book.find_by(:id => mapping[:id])&.update(:slug => mapping[:slug]) end From 55ae0768e3bc85fe23e7bea6d0bd5f612fecb165 Mon Sep 17 00:00:00 2001 From: Dilraj Somel Date: Wed, 14 Feb 2024 02:05:18 -0500 Subject: [PATCH 4/4] Add `:slug` to `show.json.jbuilder` --- app/views/books/show.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/books/show.json.jbuilder b/app/views/books/show.json.jbuilder index 2e308c6..e3911ed 100644 --- a/app/views/books/show.json.jbuilder +++ b/app/views/books/show.json.jbuilder @@ -3,6 +3,6 @@ json.key_format! :camelize => :lower json.book do - # :book => {:id, :sequence, :title, :enTitle, :enShortSummary, :enSynopsis, :artworkUrl, :numberOfChaptersReleased } - json.call(@book, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released) + # :book => {:id, :sequence, :title, :enTitle, :enShortSummary, :enSynopsis, :artworkUrl, :numberOfChaptersReleased, :slug } + json.call(@book, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released, :slug) end