このコミットが含まれているのは:
2026-06-08 00:30:20 +09:00
コミット 96df2a4eaa
12個のファイルの変更1288行の追加1行の削除
+17
ファイルの表示
@@ -0,0 +1,17 @@
class GekanatorGamesController < ApplicationController
def create
return head :unauthorized unless current_user
answers = params.require(:answers).as_json
game = GekanatorGame.create!(
user: current_user,
guessed_post_id: params.require(:guessed_post_id),
correct_post_id: params[:correct_post_id].presence,
won: bool?(:won),
question_count: params.require(:question_count),
answers:)
render json: { id: game.id }, status: :created
end
end
+18
ファイルの表示
@@ -0,0 +1,18 @@
class GekanatorGame < ApplicationRecord
belongs_to :user, optional: true
belongs_to :guessed_post, class_name: 'Post'
belongs_to :correct_post, class_name: 'Post', optional: true
validates :answers, presence: true
validates :question_count, numericality: { greater_than_or_equal_to: 0 }
validates :won, inclusion: { in: [true, false] }
validate :correct_post_required_when_lost
private
def correct_post_required_when_lost
return if won || correct_post_id.present?
errors.add(:correct_post_id, '外れた時は正解の投稿を指定してくださぃ.')
end
end
+10
ファイルの表示
@@ -11,6 +11,16 @@ class Post < ApplicationRecord
has_many :user_post_views, dependent: :delete_all
has_many :post_similarities, dependent: :delete_all
has_many :post_versions
has_many :gekanator_guessed_games,
class_name: 'GekanatorGame',
foreign_key: :guessed_post_id,
dependent: :delete_all,
inverse_of: :guessed_post
has_many :gekanator_correct_games,
class_name: 'GekanatorGame',
foreign_key: :correct_post_id,
dependent: :nullify,
inverse_of: :correct_post
has_many :parent_post_implications,
class_name: 'PostImplication',