Skip to content

Commit

Permalink
実行されたコードを保存できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
shiotomo committed Sep 30, 2018
1 parent 7680f88 commit a72cec4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/controllers/api/api_controller.rb
@@ -1,2 +1 @@
class Api::ApiController < ApplicationController
end
class Api::ApiController < ApplicationController; end
7 changes: 7 additions & 0 deletions app/controllers/api/v1/compile_controller.rb
Expand Up @@ -8,6 +8,13 @@ def exec
input = params[:input]
compiler = CodeCandy::Compiler.new

# 提出されたコードを保存
Code.create(
code: source_code,
language: language,
user_id: current_user.id
)

result = compiler.exec(language, source_code, input)

result[:stdout] = result[:stdout].force_encoding("UTF-8")
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/api/v1/judgement_controller.rb
Expand Up @@ -10,6 +10,13 @@ def exec
source_code = params[:source_code]
id = params[:answer_id]

# 提出されたコードを保存
Code.create(
code: source_code,
language: language,
user_id: current_user.id
)

judgement = CodeCandy::Judgement.new(language, source_code, id, current_user)
result = judgement.exec

Expand Down
Empty file.
2 changes: 1 addition & 1 deletion db/migrate/20180929180448_create_codes.rb
@@ -1,7 +1,7 @@
class CreateCodes < ActiveRecord::Migration[5.1]
def change
create_table :codes do |t|
t.integer :user_id, null: false
t.integer :user_id
t.text :code
t.string :language

Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -40,7 +40,7 @@
end

create_table "codes", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "user_id"
t.text "code"
t.string "language"
t.datetime "created_at", null: false
Expand Down

0 comments on commit a72cec4

Please sign in to comment.