Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slug to Book model #71

Merged
merged 4 commits into from
Feb 14, 2024
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
1 change: 1 addition & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class BooksController < ApplicationController
# NOTE: Remember to see .jbuilder
def index
@books = Book.all
end
Expand Down
12 changes: 12 additions & 0 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/views/books/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/views/books/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions db/migrate/20240214064320_add_slug_to_books.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.each do |mapping|
Book.find_by(:id => mapping[:id])&.update(:slug => mapping[:slug])
end
end
end
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading