Skip to content

Commit

Permalink
Merge pull request #86 from true-runes/development
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
nikukyugamer authored Jun 20, 2022
2 parents 555b441 + 92f95f4 commit 42f2d39
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 45 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ gem 'dotenv-rails'
gem 'faraday', '1.10.0' # 'google-cloud-language' が使えるように
gem 'google-api-client'
gem 'google-cloud-language'
gem 'jbuilder'
gem 'paper_trail'
gem 'pg'
gem 'puma'
gem 'rails'
gem 'rack-cors'
gem 'rails'
gem 'twitter'

group :development, :test do
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ GEM
io-console (0.5.11)
irb (1.4.1)
reline (>= 0.3.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jwt (2.4.1)
loofah (2.18.0)
crass (~> 1.0.2)
Expand Down Expand Up @@ -374,6 +377,7 @@ DEPENDENCIES
faraday (= 1.10.0)
google-api-client
google-cloud-language
jbuilder
paper_trail
pg
puma
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class ResultIllustrationApplicationsController < ApplicationController
def index
application_character_names = OnRawSheetResultIllustrationTotalling.order(character_name_for_public: :asc).pluck(:character_name_for_public)

render json: application_character_names.to_json
@application_character_names = OnRawSheetResultIllustrationTotalling.order(character_name_for_public: :asc).pluck(:character_name_for_public)
end
end
47 changes: 9 additions & 38 deletions app/controllers/unite_attacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class UniteAttacksController < ApplicationController
def index
return render json: all_unite_attacks.to_json if params[:title] == 'all'
if params[:title] == 'all'
@attacks = all_unite_attacks

return render 'index_all'
end

# TODO: 設定ファイル的なものから持ってきたい
convert_title_param_to_sheet_name = {
Expand All @@ -14,47 +18,13 @@ def index
'woven' => '紡時'
}[params[:title]]

attacks = OnRawSheetUniteAttack.where(sheet_name: convert_title_param_to_sheet_name)

attacks = attacks.order(kana: :asc) if params[:order] == 'kana'
@attacks = OnRawSheetUniteAttack.where(sheet_name: convert_title_param_to_sheet_name)

return_array = []
attacks.each do |attack|
return_hash = {
id: attack.id,
name: attack.name,
kana: attack.kana,
name_en: attack.name_en,
chara_1: attack.chara_1,
chara_2: attack.chara_2,
chara_3: attack.chara_3,
chara_4: attack.chara_4,
chara_5: attack.chara_5,
chara_6: attack.chara_6,
page_annotation: attack.page_annotation,
character_names: character_names(attack)
}

return_array.push(return_hash)
end

render json: return_array.to_json
@attacks = @attacks.order(kana: :asc) if params[:order] == 'kana'
end

private

# いったん愚直に
def character_names(attack)
character_names = attack.chara_1
character_names = "#{character_names}#{attack.chara_2}" if attack.chara_2.present?
character_names = "#{character_names}#{attack.chara_3}" if attack.chara_3.present?
character_names = "#{character_names}#{attack.chara_4}" if attack.chara_4.present?
character_names = "#{character_names}#{attack.chara_5}" if attack.chara_5.present?
character_names = "#{character_names}#{attack.chara_6}" if attack.chara_6.present?

character_names
end

def all_unite_attacks
return_hash = {}

Expand All @@ -69,6 +39,7 @@ def all_unite_attacks
'紡時': '幻想水滸伝 紡がれし百年の時'
}

# クエリが8回発行される
sheet_names_vs_title_names.each do |sheet_name, title_name|
attacks = OnRawSheetUniteAttack.where(sheet_name: sheet_name).order(kana: :asc)

Expand All @@ -79,7 +50,7 @@ def all_unite_attacks
id: attack.id,
name: attack.name,
name_en: attack.name_en,
character_names: character_names(attack),
character_names: Presenter::UniteAttacks.character_names(attack),
page_annotation: attack.page_annotation
}

Expand Down
15 changes: 15 additions & 0 deletions app/lib/presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Presenter
class UniteAttacks
# いったん愚直に
def self.character_names(attack)
character_names = attack.chara_1
character_names = "#{character_names}#{attack.chara_2}" if attack.chara_2.present?
character_names = "#{character_names}#{attack.chara_3}" if attack.chara_3.present?
character_names = "#{character_names}#{attack.chara_4}" if attack.chara_4.present?
character_names = "#{character_names}#{attack.chara_5}" if attack.chara_5.present?
character_names = "#{character_names}#{attack.chara_6}" if attack.chara_6.present?

character_names
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.merge! @application_character_names
14 changes: 14 additions & 0 deletions app/views/unite_attacks/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
json.array! @attacks do |attack|
json.id attack.id
json.name attack.name
json.kana attack.kana
json.name_en attack.name_en
json.chara_1 attack.chara_1
json.chara_2 attack.chara_2
json.chara_3 attack.chara_3
json.chara_4 attack.chara_4
json.chara_5 attack.chara_5
json.chara_6 attack.chara_6
json.page_annotation attack.page_annotation
json.characters Presenter::UniteAttacks.character_names(attack)
end
1 change: 1 addition & 0 deletions app/views/unite_attacks/index_all.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.merge! @attacks
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
get 'health_check', to: 'health_check#index'
get 'unite_attacks', to: 'unite_attacks#index'
get 'result_illustration_applications', to: 'result_illustration_applications#index'
get 'health_check', to: 'health_check#index', format: 'json'
get 'unite_attacks', to: 'unite_attacks#index', format: 'json'
get 'result_illustration_applications', to: 'result_illustration_applications#index', format: 'json'
end

0 comments on commit 42f2d39

Please sign in to comment.