Skip to content

Commit

Permalink
Introduce "what next instructions" to submission API response
Browse files Browse the repository at this point in the history
In clients that support it, the "what next instructions" will be
displayed after a new iteration is submitted.

This allows us to modify the message anytime, without having to wait for
users to update their cli version.
  • Loading branch information
nilbus committed Mar 19, 2017
1 parent aa7a7f9 commit ddba63e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/routes/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def current_user
def find_user
User.where(key: params[:key]).first if params[:key]
end

def site_root
request.host_with_port + '/'
end
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions api/v1/routes/iterations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Iterations < Core
locals = {
submission: attempt.submission,
domain: request.url.gsub(/#{request.path}$/, ""),
what_next_instructions: what_next_instructions(attempt)
}
pg :attempt, locals: locals
end
Expand All @@ -135,6 +136,28 @@ class Iterations < Core

pg :iterations, locals: { submissions: submissions }
end

private

def what_next_instructions(attempt)
return '' unless $flipper['cli-call-to-action'].enabled?(attempt.user)

track = attempt.iteration.track_id
exercise = attempt.iteration.slug
url = File.join('http://', site_root, 'tracks', track, 'exercises', exercise)
<<~INSTRUCTIONS
Your #{track} solution for #{exercise} has been submitted.
Programmers generally spend far more time reading code than writing it.
To benefit the most from this exercise, find 3 or more submissions that you can
learn something from, have questions about, or have suggestions for.
Post your thoughts and questions in the comments, and start a discussion.
Consider revising your solution to incorporate what you learn.
Yours and others' solutions to this problem:
#{url}
INSTRUCTIONS
end
end
end
end
1 change: 1 addition & 0 deletions api/v1/views/attempt.pg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node language: submission.problem.language
node slug: submission.slug
node name: submission.problem.name
node iteration: submission.version
node what_next_instructions: what_next_instructions

# deprecated
node id: submission.key
Expand Down
1 change: 1 addition & 0 deletions test/api/assignments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def app
attr_reader :alice
def setup
super
$flipper['cli-call-to-action'].enable
@alice = User.create(username: 'alice', github_id: 1)
Language.instance_variable_set(:"@by_track_id", "fake" => "Fake")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"slug": "one",
"name": "One",
"iteration": 1,
"what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n",
"id": "<id>",
"status": "saved",
"track": "fake",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"slug": "one",
"name": "One",
"iteration": 1,
"what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n",
"id": "<id>",
"status": "saved",
"track": "fake",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"slug": "one",
"name": "One",
"iteration": 1,
"what_next_instructions": "Your fake solution for one has been submitted.\n\nProgrammers generally spend far more time reading code than writing it.\nTo benefit the most from this exercise, find 3 or more submissions that you can\nlearn something from, have questions about, or have suggestions for.\nPost your thoughts and questions in the comments, and start a discussion.\nConsider revising your solution to incorporate what you learn.\n\nYours and others' solutions to this problem:\nhttp://example.org/tracks/fake/exercises/one\n",
"id": "<id>",
"status": "saved",
"track": "fake",
Expand Down

0 comments on commit ddba63e

Please sign in to comment.