47 行
1.3 KiB
Ruby
47 行
1.3 KiB
Ruby
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),
|
|
answer: params.require(:answer))
|
|
|
|
if suggestion.save
|
|
render json: {
|
|
id: suggestion.id,
|
|
count: game.question_suggestions.count
|
|
}, status: :created
|
|
else
|
|
render_validation_error suggestion
|
|
end
|
|
end
|
|
|
|
def ai_convert
|
|
return head :not_found unless current_user&.admin?
|
|
|
|
suggestion = GekanatorQuestionSuggestion.find_by(id: params[:id])
|
|
return head :not_found unless suggestion
|
|
if Gekanator::AiRunBudget.exceeded_after_next_run?
|
|
suggestion.gekanator_ai_runs.create!(
|
|
model: 'budget_guard',
|
|
status: 'blocked_budget',
|
|
input_tokens: 0,
|
|
output_tokens: 0,
|
|
estimated_cost_jpy: 0)
|
|
return head :payment_required
|
|
end
|
|
|
|
Gekanator::QuestionSuggestionAiConverter.call(
|
|
suggestion: suggestion,
|
|
user: current_user)
|
|
head :no_content
|
|
rescue NotImplementedError
|
|
head :not_implemented
|
|
end
|
|
end
|