このコミットが含まれているのは:
2026-06-09 01:29:43 +09:00
コミット a1ea35a7ec
8個のファイルの変更306行の追加90行の削除
+19
ファイルの表示
@@ -0,0 +1,19 @@
class GekanatorQuestionSuggestionsController < ApplicationController
def create
return head :not_found unless current_user&.admin?
game = GekanatorGame.find_by(id: params.require(:gekanator_game_id))
return head :not_found unless game
suggestion = GekanatorQuestionSuggestion.new(
gekanator_game: game,
user: current_user,
question_text: params.require(:question_text))
if suggestion.save
render json: { id: suggestion.id }, status: :created
else
render_validation_error suggestion
end
end
end
+3
ファイルの表示
@@ -2,6 +2,9 @@ class GekanatorGame < ApplicationRecord
belongs_to :user
belongs_to :guessed_post, class_name: 'Post'
belongs_to :correct_post, class_name: 'Post'
has_many :question_suggestions,
class_name: 'GekanatorQuestionSuggestion',
dependent: :delete_all
validates :answers, presence: true
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
+21
ファイルの表示
@@ -0,0 +1,21 @@
class GekanatorQuestionSuggestion < ApplicationRecord
MAX_QUESTIONS_PER_GAME = 1
belongs_to :gekanator_game
belongs_to :user
validates :question_text, presence: true, length: { maximum: 1000 }
validates :processed, inclusion: { in: [true, false] }
validate :question_suggestion_limit_per_game, on: :create
private
def question_suggestion_limit_per_game
return if gekanator_game_id.blank?
count = GekanatorQuestionSuggestion.where(gekanator_game_id:).count
if count >= MAX_QUESTIONS_PER_GAME
errors.add(:base, '質問追加数を超えてゐます.')
end
end
end
+3
ファイルの表示
@@ -65,6 +65,9 @@ Rails.application.routes.draw do
namespace :gekanator do
resources :games, only: [:create], controller: '/gekanator_games'
resources :question_suggestions,
only: [:create],
controller: '/gekanator_question_suggestions'
end
resources :users, only: [:create, :update] do
+14
ファイルの表示
@@ -0,0 +1,14 @@
class CreateGekanatorQuestionSuggestions < ActiveRecord::Migration[8.0]
def change
create_table :gekanator_question_suggestions do |t|
t.references :gekanator_game,
null: false,
foreign_key: { on_delete: :cascade }
t.references :user, null: false, foreign_key: true
t.text :question_text, null: false
t.boolean :processed, null: false, default: false
t.timestamps
end
end
end
生成ファイル
+14 -1
ファイルの表示
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2026_06_07_000000) do
ActiveRecord::Schema[8.0].define(version: 2026_06_08_000000) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
@@ -63,6 +63,17 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_07_000000) do
t.check_constraint "`question_count` >= 0", name: "chk_gekanator_games_question_count_nonnegative"
end
create_table "gekanator_question_suggestions", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "gekanator_game_id", null: false
t.bigint "user_id", null: false
t.text "question_text", null: false
t.boolean "processed", default: false, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["gekanator_game_id"], name: "index_gekanator_question_suggestions_on_gekanator_game_id"
t.index ["user_id"], name: "index_gekanator_question_suggestions_on_user_id"
end
create_table "ip_addresses", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.binary "ip_address", limit: 16, null: false
t.datetime "banned_at"
@@ -496,6 +507,8 @@ ActiveRecord::Schema[8.0].define(version: 2026_06_07_000000) do
add_foreign_key "gekanator_games", "posts", column: "correct_post_id"
add_foreign_key "gekanator_games", "posts", column: "guessed_post_id"
add_foreign_key "gekanator_games", "users"
add_foreign_key "gekanator_question_suggestions", "gekanator_games", on_delete: :cascade
add_foreign_key "gekanator_question_suggestions", "users"
add_foreign_key "material_versions", "materials"
add_foreign_key "material_versions", "materials", column: "parent_id"
add_foreign_key "material_versions", "tags"