class GekanatorGamesController < ApplicationController def create return head :not_found unless current_user&.admin? guessed_post_id = params.require(:guessed_post_id) correct_post_id = params[:correct_post_id].presence answers = params.require(:answers).as_json game = GekanatorGame.new( user: current_user, guessed_post_id:, correct_post_id:, won: correct_post_id.present? && guessed_post_id.to_i == correct_post_id.to_i, question_count: answers.length, answers:) if game.save render json: { id: game.id }, status: :created else render json: { errors: game.errors.full_messages }, status: :unprocessable_entity end end end